SQL 循环遍历结果集



 Declare   @row int,  --行记录数
@count int,--总记录数

@id int --你需要的结果


 select @count=COUNT(1),@row =1 from 表名
 
 SELECT ROW_NUMBER() OVER (ORDER BY id ASC) rowid,* into #t from 表名
 
 while @row <= @count --循环开始
BEGIN
select @id=id from #t where rowid=@row --当前列的数据
//这里编写自己的逻辑
set @row=@row +1 
END

drop table #t
 
posted @ 2017-03-13 23:19  仅此而已。  阅读(6630)  评论(0编辑  收藏  举报