游标

--SELECT * FROM Students

declare mycursor cursor for
select * from Students

open mycursor
declare @Id int, @Name nvarchar(20), @Age int, @Sex bit, @Flag bit;
fetch next from mycursor into @id,@name,@age,@sex,@flag    

while @@FETCH_STATUS = 0
begin    
    select @Id,@name
    fetch next from mycursor into @id,@name,@age,@sex,@flag    
end
close mycursor

deallocate mycursor
原文地址:https://www.cnblogs.com/superfeeling/p/12597097.html