TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kacey Ezerioha
NA
37
0
Urgent help needed here for a school Project
May 10 2011 12:59 AM
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
Reply
Answers (
6
)
Need help in SQL server and C#.net problem.
What are the different index configurations a table can have?