I am trying to get the sum of the pointsEarned
column and the sum of the pointsPossible
column. I want to turn this into a percentage. My problem is that my SP always returns 0, even when there are rows with the given enrollmentId
that have values for the previous columns.
What am I doing wrong?
ALTER PROCEDURE GetPercentage
@enrollmentId int
AS
BEGIN
DECLARE @pointsEarned int;
DECLARE @pointsPossible int;
SET NOCOUNT ON;
SELECT
@pointsEarned = CAST(SUM(pointsEarned) OVER() AS decimal),
@pointsPossible = CAST(SUM(pointsPossible) OVER() AS decimal)
FROM
Assignments
WHERE
enrollmentId = @enrollmentId
RETURN @pointsEarned / @pointsPossible
END
GO
This is the database table:
I execute the stored procedure and passed in the enrollmentId
of 69 and it still returns 0.