I am using following procedure to retrieve total presents and absents by using pivot query….i want to SUM of Presents[P] And Absents[A] And then calculate percentage
ALTER PROCEDURE [dbo].[GetAttendence](@Course_Id varchar(30), @Semester varchar(10))
AS
SELECT DISTINCT Enroll_Number, Course_Id, Semester, Isnull([P],0)
As Presents, Isnull([A],0) As Absents
FROM (SELECT Enroll_Number, Course_Id, Semester, Flag from Attendence ) ps
pivot(Count(Flag) for Flag in ([P],[A])) as pvt
WHERE Course_Id = @Course_Id and Semester = @Semester
This is Forula to implement….
Sum = Presents + Absents
Percentage = ((Presents / Sum) * 100)
Try this: