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这基本上是通过一个光标返回一个单独的位置编号。位置数字被存储为游标中的一个变量,我需要在一个while循环中使用它,该循环迭代特定的次数(20)。返回给我的只是整个位置号码列表的游标,而不是使用update语句遍历while循环。
发布于 2012-05-10 22:09:58
虽然游标和循环通常是解决问题的错误方法,但我现在没有时间弄清楚您到底在做什么来建议基于集合的解决方案,但说真的,您需要开始在集合中思考,并停止思考循环。
但是你的问题是@i是null,null不是<20。
看看这个测试我的理论
declare @i int
if @i<20 print'hi'
else print 'bye'https://stackoverflow.com/questions/10535698
复制相似问题