游标

declare @变量 nvarchar(50)

DECLARE Customer_cursor CURSOR 

    
FOR  select 变量 from 数据表
    
    
OPEN Customer_cursor
    
FETCH NEXT FROM Customer_cursor 
    
INTO @变量
   
       
WHILE @@FETCH_STATUS = 0
         
Begin
            
print @变量
         


     
FETCH NEXT FROM Customer_cursor 
     
INTO @变量
     
End

CLOSE Customer_cursor
DEALLOCATE Customer_cursor
原文地址:https://www.cnblogs.com/Bruce_H21/p/784159.html