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.
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:Result:
So, your proc would be: