try:
open cursor1
fetch ...
while @@fetch_status =0
begin
 open cursor2
 fetch ... ...
 while @@fetch_status =0
 begin
 fetch ... ...
 end
 close cursor2
 deallocate cursor2
fetch ...
end
close cursor1
deallocate cursor1

解决方案 »

  1.   


    deallocate 是什么用的阿 ?
      

  2.   


        这样的循环是好象是不管用的,
    因为@@FETCH_STATUS 是全局的,
    我试过了,不行,
      

  3.   


      我调试发现加和不加Deallocate 是有区别的
      再试
      

  4.   

    while @@FETCH_STATUS  = 0
         while @@FETCH_STATUS = 2
         end;
       end;
      

  5.   

    open cursor1
    fetch ...
    while @@fetch_status =0
    begin
     open cursor2
     fetch ... ...
     while @@fetch_status =0
     begin
     fetch ... ...
     end
     close cursor2
     
    fetch ...
    end
    close cursor1deallocate cursor1
    deallocate cursor2
    试过了没错
    确实@@fetch_status是全局变量
    当执行fetch语句后这个全局变量就被赋予新值
    所以可以看出
    在循环判断之前@@fetch_status已经被赋予正确的值了