遍歷查詢結果集,update數據


 

 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

 


免責聲明!

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



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