码迷,mamicode.com
首页 > 其他好文 > 详细

遍历查询结果集,update数据

时间:2017-12-12 21:58:02      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:upd   print   blog   sel   begin   cas   color   date   let   

 

技术分享图片
 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数据

标签:upd   print   blog   sel   begin   cas   color   date   let   

原文地址:http://www.cnblogs.com/green-jcx/p/8028848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!