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
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM