存储过程默认参数问题
创建一个存储过程,实现获取指定学号的所有课程成绩,输出为:学号、姓名、课程名、成绩,如果不指定学号,则输出所有学生的上述几个字段信息。
create procedure query(@xh char(6)=xh)asif not exists(select * from xsb where xh=@xh)print '学号不存在'elsebeginselect * from(select xsb.xh,xm,kcm,cj from xsb join cjb join kcbon cjb.kch=kcb.kchon xsb.xh=pcjb.xh)as temp(xh,xm,kcm,cj) where xh=@xhendexecute query '081102'
--默认*为全部create procedure query(@xh char(6) = '*')asif isnull(@xh,'*') = '*'begin select xsb.xh,xsb.xm,kcb.kcm,cjb.cj from xsb,cjb,kcb where cjb.kch = kcb.kch and xsb.xh = cjb.xhendelsebegin select xsb.xh,xsb.xm,kcb.kcm,cjb.cj from xsb,cjb,kcb where cjb.kch = kcb.kch and xsb.xh = cjb.xh and xsb.xh = @xhend