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ループ内で使用する必要があります。返されるのは、ロケーション番号のリスト全体に対してカーソルが移動しているだけですが、updateステートメントでwhileループを繰り返すことはありません。