1. 程式人生 > >遍歷查詢結果集,update數據

遍歷查詢結果集,update數據

cas code view sed closed clas alt upd begin

技術分享圖片
 1 set rowcount 0
 2 select NULL mykey, * into #mytemp from  dbo.DIM_DISTRIBUTOR
 3 
 4 set rowcount 1
 5 update #mytemp set mykey = 1
 6 
 7 declare @i int 
 8 set @i=1    
 9 while @@rowcount > 0
10 begin
11     set rowcount 0
12     select * from #mytemp where mykey = 1
13   
14     declare @zj
varchar(222) 15 select @zj=DISTRIBUTORID from #mytemp where mykey = 1 16 print @i 17 18 update DIM_DISTRIBUTOR set NAME=用戶測試數據+CAST(@i as varchar(222)) where DISTRIBUTORID=@zj 19 20 set @i=@i+1 21 delete #mytemp where mykey = 1 22 set rowcount 1 23 update
#mytemp set mykey = 1 24 end 25 set rowcount 0
View Code

遍歷查詢結果集,update數據