table. I came up with this code below and it's given me a result of -6 and some strange messages which is ofcourse not normal.
Please I would like someone to check it out below and find out what I'm not doing right. Many thanks in advance.
CREATE PROCEDURE [dbo].[GPAComputation]
(
@StudentId int
)
AS
BEGIN
DECLARE @GPA decimal(4,2)
DECLARE @CreditHours int
SELECT @CreditHours = (SELECT c.CreditHours FROM [Course]c WHERE c.CourseId = (SELECT r.CourseId FROM [Result]r WHERE r.CourseId = c.CourseId))
SELECT @GPA = CONVERT(decimal(4,2), SUM(@CreditHours * CAST(CASE r.Grades WHEN 'A' THEN 5 WHEN 'B' THEN 4 WHEN 'C' THEN 3 WHEN 'D' THEN 2
WHEN 'E' THEN 1 ELSE 0 END AS int )) / SUM(@CreditHours))
FROM [Result]r
WHERE
r.StudentId = @StudentId
END