循环select查询结果集

--标记id
--每次查询特定列比标记id大的第一条数据,
--同时更新标记id,直到查询结果为空
declare @id varchar(50)
set @id=''
    while 1=1
    begin
        select top 1 @id=id from T_SGZ where id>@id order by id 
        if @@ROWCOUNT=0
            break
            
        print(@id)
    end
原文地址:https://www.cnblogs.com/sheeva/p/4646679.html