雷霆战机哪个宠物最好:精通T-SQL的大侠请进,帮忙改个错.

来源:百度文库 编辑:中科新闻网 时间:2024/05/15 19:25:08
使用游标语句修改InfoDB数据库中学生表中学号为‘200305187’学生的学分,如果学分大于100则给该生增加5个学分,小于或等于100则增加6个学分。
use InfoDB
go
Declare my_cursor cursor for
Select 学号,学分 from 学生表
Where 学号 = '200305187'
Open my_cursor
Petch next from my_cursor
While @@fetch_staus =0
Begin
If 学分 > 100
begin
学分= 学分+5
End
Else
Begin
学分= 学分+6
End
End
Close my_cursor
Deallocate my_cursor

不知道怎么改了,麻烦大侠帮忙改错.拜谢m-____-m

Declare my_cursor cursor for
Select 学号,学分 from 学生表 Where 学号 = '200305187'
Open my_cursor
declare @xf,@xh int
Fetch next from my_cursor into @xh,@xf
While @@fetch_status =0
Begin
If @xf>100
begin
update 学生表 set 学分=学分+5 where 学号=@xh
End
Else
Begin
update 学生表 set 学分=学分+6 where 学号=@xh
End
Fetch next from my_cursor into @xh,@xf
End
Close my_cursor
Deallocate my_cursor

游标我不会不过可以写出等价的sql语句
update 学生表 set 学分=学分+5 where 学号 = '200305187' and 学分>100
update 学生表 set 学分=学分+6 where 学号 = '200305187' and 学分<=100
还有我觉得你的Petch next from my_cursor 应该去掉