循环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

 

posted @ 2015-07-14 21:41  叫我家宝  阅读(750)  评论(0编辑  收藏  举报