创建一个存储过程,用于查询指定课程号的课程

来源:互联网 发布:木制弹弓尺寸图纸数据 编辑:程序博客网 时间:2024/05/23 18:33

创建一个存储过程,用于查询指定课程号的课程

--是否被学生选修,如果有学生选修,
--
则在该过程中设置一个输出参数用于
--
返回选修该课程的学生人数,
--
然后让该过程返值1
--
如果没有被任何一个学生选修,则该过程返回值2
IF exists (select* from sys.objects where name='CunChu_lx_cno_course' and type='p'  )
  drop proc CunChu_lx_cno_course
go
create procedure CunChu_lx_cno_course
 @out int output,
 @in  varchar(10)=1
as
 select @out=count(*)from sc
 where
cno=@in
 if(@out=0)
   begin
     set @out='2'
   end
 else
   begin
     set @out='1'
   end