create proc cal_gpa @sno char(7),@gpa decimal output
as
declare @gp decimal,@sumgp decimal
select @sumgp=sum(@gp)
from sc,courses
where sc.sno=@sno and sc.cno=courses.cno
and @gp in (select "@gp"=case grade>=85 then 4*credit
grade>=75 then 3*credit
grade>=60 then 2*credit
else 1*credit
from courses,sc
where courses.cno=sc.cno
end)
try it:)
as
declare @gp decimal,@sumgp decimal
select @sumgp=sum(@gp)
from sc,courses
where sc.sno=@sno and sc.cno=courses.cno
and @gp in (select "@gp"=case grade>=85 then 4*credit
grade>=75 then 3*credit
grade>=60 then 2*credit
else 1*credit
from courses,sc
where courses.cno=sc.cno
end)
try it:)
解决方案 »
- 帮忙修改一个存储过程的函数 在线等高人
- 请问怎样修改已经存在的datetime类型的值?比如:有一个datetime类型的值是2007-1-9 21:26:44,要把2007该为2008
- 如何在查询分析器中获得存储过程中的RETURN值?
- 在ASP里实现数据库备份并下载,但下载的文件.bak不能用
- 请教一个统计报表的sql serve 语句 谢谢大家帮助!
- SQL_2005_All简体中文开发版DVD 怎么装不上去啊
- 请问如何编写实现如下功能的查询语句(只要一句)
- SQL讀Excel問題
- ora-00054的错误名是什么?
- 报表查询
- 用SQL SERVER创建的数据库是否要有SQL SERVER服务器端才能用!!
- ●●检索记录所需的时间长短与数据表的总记录数没有关系,只跟要检索出来的记录数有关系。这话对不?●●
asdeclare @gp decimal,@sumgp decimal
select @sumgp=sum(@gp)
from sc,courses
where sc.sno=@sno and sc.cno=courses.cno
and @gp in (select case when grade>=85 then 4*credit when grade>=75 then 3*credit
when grade>=60 then 2*credit
else 1*credit
from courses,sc
courses.cno=sc.cno
end)
???
grade>=75 then 3*credit
grade>=60 then 2*credit
else 1*credit
from courses,sc
courses.cno=sc.cno
end
返回的是记录集,而不是直
具体阐述如下:
要求:根据SNO参数,输出并显示该学生的GPA值。
附GPA的计算方法:
GRADE>=85,GP=4
GRADE>=75,GP=3
GRADE>=60,GP=2
GRADE<60,GP=1
GPA=(∑GP*CREDIT)/(∑CREDIT)。
CREDIT是课程的学分。
源表的结构:
STUDENTS(SNO,SNAME,SEX,HEIGHT,BDATE,DEPARTMENT)
COURSES(CNO,CNAME,CREDIT,SEMESTER)
SC(CNO,SNO,GRADE)
as
select @gpa=sum(isnull(case when a.grade>=85 then 4 when a.grade>=75 then 3 when a.grade>=60 then 2 else 1 end,1)*isnull(b.credit,1))/isnull(sum(b.credit),1)
from sc a,courses b where a.cno=b.cno
我不是很理解isnull的用法。
多谢多谢
---用大力替换null值