6
Answers

Urgent help needed here for a school Project

Kacey Ezerioha

Kacey Ezerioha

13y
2.6k
1
Pls I need help in this stored procedure in sql server 2008 for calculating GPA for student for a project I'm creating. Based on the formula to calculate gpa = Total Grade Points/Total Credit hours, this is what I did;

I have to tables Course and Result and I intend to pick the credit hours of a particular course (foreign key) in the Result table from the Course 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

Answers (6)