随笔 - 797  文章 - 2  评论 - 56  阅读 - 158万

tsql 循环id读取

复制代码
declare @IDList as varchar(max)
declare @ID as int 
declare @i as int
set @IDList=''

select @IDList=@IDList + cast(id as varchar(50)) + ',' from table
while CharIndex(',',@IDList)<>0
Begin
    set @ID = SubString(@IDList,1,CharIndex(',',@IDList)-1)
    print(@ID)
    
    set @IDList = Replace(','+@IDList,','+Cast(@ID as nvarchar(50))+',','')
End
复制代码

 

posted on   一粒沙  阅读(417)  评论(0编辑  收藏  举报
努力加载评论中...
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示