Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:12:41+00:00 2026-06-07T04:12:41+00:00

Id Answer NoOfComments 18 1 2 19 2 0 20 3 0 21 4

  • 0
Id  Answer  NoOfComments
18      1        2
19      2        0
20      3        0
21      4        0
22      5        1

The datas given above is the output obtained from following StoredProcedure.

 ALTER PROCEDURE [dbo].[BlogAnswerByQuestionId]
(
    @QuestionId int
)
AS
BEGIN
    SELECT [HRM_BlogAnswer].[Id] as Id
          ,[HRM_BlogAnswer].[Answer]
          ,(SELECT COUNT(*) FROM HRM_BlogVote  WHERE HRM_BlogVote.AnswerId  =[HRM_BlogAnswer] .[Id]) AS NoOfComments

        FROM [HRM_BlogAnswer] 
    WHERE [HRM_BlogAnswer].[QuestionId] = @QuestionId


END

Now I need to find the percentage value of each answer according to the value in the field NoOfComments. I can give some more information.
1.datas in table HRM_blogquestion as follows.

Id  Question    CreatedDate          CreatedBy
8   tttt    2012-07-03 17:36:47.513        1

2.datas in table HRM_Bloganswer as follows

Id  QuestionId  Answer
18  8             1
19  8             2
20  8             3
21  8             4
22  8             5

3.datas in table HRM_Blogvote as follows

Id  QuestionId  AnswerId    EmployeeId
19  8                18        1
23  8                22        24
24  8                18        25

From these table datas i write the above SP And now i need to find percentage of voted answers

Please help me to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:12:41+00:00Added an answer on June 7, 2026 at 4:12 am

    Rather than creating this table @Results, you could turn your existing query into a common table expression, and query that instead. The final query is the one you want:

    declare @Results table (
        Id int not null,
        Answer int not null,
        NoOfComments int not null
    )
    insert into @Results (Id,Answer,NoOfComments) values
    (18,      1,        2),
    (19,      2,        0),
    (20,      3,        0),
    (21,      4,        0),
    (22,      5,        1)
    
    select *,((NoOfComments * 100.0) / SUM(NoOfComments) OVER (PARTITION BY (1))) as Pcnt
    from @Results
    

    Result:

    Id          Answer      NoOfComments Pcnt
    ----------- ----------- ------------ ---------------------------------------
    18          1           2            66.666666666666
    19          2           0            0.000000000000
    20          3           0            0.000000000000
    21          4           0            0.000000000000
    22          5           1            33.333333333333
    

    So, your proc would be:

     ALTER PROCEDURE [dbo].[BlogAnswerByQuestionId]
    (
        @QuestionId int
    )
    AS
    BEGIN
        ;With Results as (
        SELECT [HRM_BlogAnswer].[Id] as Id
              ,[HRM_BlogAnswer].[Answer]
              ,(SELECT COUNT(*) FROM HRM_BlogVote  WHERE HRM_BlogVote.AnswerId  =[HRM_BlogAnswer] .[Id]) AS NoOfComments
    
            FROM [HRM_BlogAnswer] 
        WHERE [HRM_BlogAnswer].[QuestionId] = @QuestionId
        )
        select *,((NoOfComments * 100.0) / SUM(NoOfComments) OVER (PARTITION BY (1))) as Pcnt
        from Results
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The answer from TcKs gave me an idea, thus i tried following: system(mailto:thomas.muster@domainname.com?subject=Test); and
In answer to the following question: How to convert MatchCollection to string array Given
Answer : Implemented using Curl... $file = http://abc.com/data//output.txt; $ch = curl_init($file); $fp = @fopen(out.txt,
THE ANSWER THAT WORKED FOR ME BASED ON AN ANSWER GIVEN while($post = mysql_fetch_array($tags))
(ANSWER) How to export some Geography data from a Microsoft Sql Server 2008. You'll
This answer of mine generated some comments claiming that the following construct is not
ANSWER : The fix for this problem is this : Change selector from $('#Button3')
The answer given in pausing MediaPlayer works perfectly well for a Music Player. In
[ANSWER] Thanks everyone! The code to solved the problem below is: SELECT ID FROM
An answer to one of my questions included the following line of code: label

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.