declare @i int
declare @skool float
declare schoolCursor cursor for
select distinct choice from tempstuas
open schoolCursor
fetch next from schoolCursor into @skool
while @@fetch_status = 0
begin
while @i < 20
begin
update top(1) tempstuas set cnt=@i where cnt = '' and cat = 1 and choice=@skool
update top(1) tempstuas set cnt=@i where cnt = '' and cat = 2 and choice=@skool
update top(1) tempstuas set cnt=@i where cnt = '' and cat=3 and choice=@skool
set @i = @i + 1
end
fetch next from schoolCursor
end
close schoolCursor
deallocate schoolCursor
这基本上是通过一个返回单个位置编号的游标。位置编号存储为来自游标的变量,我需要在循环特定次数 (20) 的 while 循环中使用该变量。我返回的只是整个位置编号列表的光标,但不会使用更新语句遍历 while 循环。