1 create proc countPassRate 2 @cno char(9), 3 @passrate char(5) output 4 as 5 select @passrate=cast(cast(sum(case when grade>=60 then 1 else 0 end)*100/(count(*)*1.0)as numeric(5,2)) as nvarchar) from sc 6 where cno=@cno 7 print @passrate+‘%‘ 8 go 9 10 exec countPassRate ‘8‘,null 11 go 12 create proc st_info5 13 @sname nchar(6) 14 as 15 select cname,grade from sc join course on sc.cno=course.cno 16 where sno=( 17 select sno from student 18 where sname=@sname 19 ) 20 exec st_info5 ‘赵菁菁‘ 21 update course set Ccredit=5 22 where cno=‘5‘ 23 24 declare my_cursor cursor scroll dynamic 25 for 26 select sno,sname from student 27 declare @_sno char(9) 28 declare @_sname char(20) 29 declare @_cno char(20) 30 declare @_cname char(20) 31 declare @_credit int 32 declare @_scredit char(20) 33 open my_cursor 34 fetch next from my_cursor into @_sno,@_sname 35 while(@@fetch_status=0) 36 begin 37 print @_sno+‘ ‘+@_sname 38 declare my_cursor2 cursor scroll dynamic 39 for 40 select course.Cno,cname,Ccredit from course join sc on course.cno=sc.cno 41 where sno=@_sno 42 open my_cursor2 43 fetch next from my_cursor2 into @_cno,@_cname,@_credit 44 while(@@fetch_status=0) 45 begin 46 select @_scredit=cast(@_credit as nvarchar) 47 print @_cno+@_cname+@_scredit 48 fetch next from my_cursor2 into @_cno,@_cname,@_credit 49 end 50 close my_cursor2 51 deallocate my_cursor2 52 fetch next from my_cursor into @_sno,@_sname 53 end; 54 close my_cursor 55 deallocate my_cursor
时间: 2024-10-15 04:01:46