I found one mistake: no comma after "@v_totcredit int = 0,"
-----Original Message-----
From: MinhCDao@a... [mailto:MinhCDao@a...]
Sent: Thursday, November 16, 2000 11:37 PM
To: sql language
Subject: [sql_language] SQLServer7 Procedure Error
--part1_8e.d0794ec.2744d376_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Hi there
Please help me to fix the error of the procedure to calculate student GPA in
SQLServer7. I really appriciate.
CREATE PROC cal_gpa
@p_sid int,
@v_grade Char,
@v_score int,
@v_sgpa Double = 0.0,
@v_totcredit int = 0,
DECLARE @tblreg_students VARCHAR(255)
DECLARE @tblcourses VARCHAR(255)
DECLARE MyCursor CURSOR FOR
SELECT a.grade, b.credits
FROM tblreg_students a, tblcourses b
WHERE a.CID = b.CID
AND a.SID = p_sid
@p_gpa int CURSOR VARYING OUTPUT
AS
OPEN MyCursor
FOR v IN MyCursor
v_grade = v.grade
IF v_grade = 'A' THEN
v_score = 4
ELSE v_grade = 'B' THEN
v_score = 3
ELSE v_grade = 'C' THEN
v_score = 2
ELSE v_grade = 'D' THEN
v_score = 1
ELSE
v_score = -1
v_totcredit = v_totcredit + v.credits
v_sgpa = v_sgpa + v.credits * v_score
NEXT
END
p_gpa = v_sgpa / v_totcredit
CLOSE MyCursor
SELECT p_gpa
Errors:
Server: Msg 170, Level 15, State 1, Procedure cal_gpa, Line 5
Line 5: Incorrect syntax near '='.
Server: Msg 170, Level 15, State 1, Procedure cal_gpa, Line 16
Line 16: Incorrect syntax near '@p..._gpa'.
Server: Msg 156, Level 15, State 1, Procedure cal_gpa, Line 21
Incorrect syntax near the keyword 'THEN'.
Minh C. Dao