SQL——游标循环的写法

sql里写循环,还是得用游标写。

插入代码

if object_id('tempdb..#t1') is not null drop table #t1

select 'DanHao' as F1
into #t1
union all 
select '1ewe'

declare @field varchar(50) 


declare cs cursor  for select * from #t1
open cs

fetch next from cs into @field

while @@FETCH_STATUS =0
begin
    select @field
    fetch next from cs into @field
end

close cs
deallocate cs

完了

原文地址:https://www.cnblogs.com/fabao/p/12827710.html