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 [email protected] where cnt = '' and cat = 1 and [email protected]
update top(1) tempstuas set [email protected] where cnt = '' and cat = 2 and [email protected]
update top(1) tempstuas set [email protected] where cnt = '' and cat=3 and [email protected]
set @i = @i + 1
end
fetch next from schoolCursor
end
close schoolCursor
deallocate schoolCursor
이것은 기본적으로 개별 위치 번호를 반환하는 커서를 통해 진행됩니다. 위치 번호는 특정 시간 (20)을 반복하는 while 루프 내에서 사용해야하는 커서의 변수로 저장됩니다. 반환되는 것은 위치 번호의 전체 목록에 대해 커서를 이동하는 것 뿐이며 while 루프를 통해 update 문을 반복하지는 않습니다.A While 루프 while 루프 while 루프 - SQL
1)이 시험을 볼 수 없습니다 < (20)
입니다. 'WHILE' 명령문 바로 앞에'SET @i = 1' (또는 0 또는 필요한 것)을 넣으시겠습니까? 2). 커서 및 While 루프를 사용하지 않고이를 수행 할 수있는 방법을 찾아보십시오. – MatBailie