#2
mywisdom882016-11-24 20:30
|
利用学生学号查询该名学生在指定学年,指定学期所获得的学分数以及还未获得的学分数,若该门课程尚无成绩或成绩小于60分,
则为尚未获得的学分,结果以变量形式输出(OUTPUT)。
CREATE PROCEDURE stu_proc_3
@Sno NCHAR(6), @academicyear int, @term int,
@GetCredits int OUTPUT, @NotGetCredits int OUTPUT
AS
SELECT @GetCredits=SUM(Ccredit)
FROM jx_Reports R, jx_Courses C
WHERE AND Sno=@Sno AND YEAR(Racademicyear)=@academicyear
AND Rterm=@term AND Score>=60
SELECT @NotGetCredits=SUM(Ccredit)
FROM jx_Reports R, jx_Courses C
WHERE AND Sno=@Sno AND YEAR(Racademicyear)=@academicyear
AND Rterm=@term AND (Score<60 OR Score IS NULL)
执行:
DECLARE @GetCredits int
DECLARE @NotGetCredits int
EXEC stu_proc_3 '101103',2010,1,@GetCredits OUTPUT,@NotGetCredits OUTPUT
SELECT 学号='101103', 已获学分=@GetCredits
未获学分=ISNULL(@NotGetCredits,0)