码迷,mamicode.com
首页 > 数据库 > 详细

sql实验七已完成

时间:2015-12-02 16:10:12      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

 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

 

sql实验七已完成

标签:

原文地址:http://www.cnblogs.com/linkzijun/p/5013255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!