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:)

解决方案 »

  1.   

    create proc cal_gpa @sno char(7),@gpa decimal output
    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)
    ???
      

  2.   

    select "@gp"=case   grade>=85 then 4*credit
                     grade>=75 then 3*credit
                     grade>=60 then 2*credit
                     else 1*credit
                   from courses,sc
                   courses.cno=sc.cno
                   end
    返回的是记录集,而不是直
      

  3.   

    就是不会处理这个问题:(,怎样可以只返回一个值呢?
    具体阐述如下:
    要求:根据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)
      

  4.   

    try:create proc cal_gpa @sno varchar(7),@gpa numeric(10,2) output
    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
      

  5.   

    可以了。能解释一下吗?
    我不是很理解isnull的用法。
    多谢多谢
      

  6.   

    select isnull(null,'大力')
    ---用大力替换null值