帮忙看看这个问题
时间:2011-11-17
来源:互联网
@midcount int,@curcount int,@customer_guid varchar(36),@objective_guid varchar(36)
declare cursor1 cursor for select newstaffid from bk1 where flagstr=1
open cursor1
fetch next from cursor1 into @powerstaffid
while @@fetch_status=0
begin
declare cursor3 cursor for select oldstaffid from bk1 where flagstr<>1 and newstaffid=@powerstaffid
open cursor3 fetch next from cursor3 into @newstaffid
while @@FETCH_STATUS = 0
begin
select top 1 @customer_guid= customer_guid from customer20111117 where owner=@powerstaffid
update customer20111117 set owner=@newstaffid where customer_guid =@customer_guid
select top 1 @objective_guid= objective_guid from objective20111117
where customer_guid =@customer_guid and objectivetype_id in('17974B','5172AF') and objectivestatus='OPEN'
update objective20111117 set handleby_id=@newstaffid where objective_guid=@objective_guid
update oblist20111117 set handleby_id=@newstaffid where objective_guid=@objective_guid
insert into tl(newstaffid,powerstaffid,customer_guid,objective_guid)values
(@newstaffid,@powerstaffid,@customer_guid,@objective_guid)
fetch next from cursor3 into @newstaffid
end
fetch next from cursor1 into @powerstaffid
close cursor3
deallocate cursor3
end
close cursor1
deallocate cursor1
是一个游标嵌套循环的语句块,但是我执行之后发现定义的cursor1里面还没有执行完毕,我觉得是我逻辑上的问题,麻烦大家帮忙看看这个语句块有那些问题 感谢了
作者: oceantang 发布时间: 2011-11-17
close cursor3
deallocate cursor3
fetch next from cursor1 into @powerstaffid
end
close cursor1
deallocate cursor1
紅色這段放錯位置
作者: roy_88 发布时间: 2011-11-17
作者: roy_88 发布时间: 2011-11-17
end
close cursor3
deallocate cursor3
fetch next from cursor1 into @powerstaffid
end
close cursor1
deallocate cursor1
紅色這段放錯位置
我这样也试过了,也不行
作者: oceantang 发布时间: 2011-11-17
先關游標再執行下一條
麻烦这位大哥指点下,怎么做
作者: oceantang 发布时间: 2011-11-17
DECLARE @powerstaffid VARCHAR(6) , @newstaffid VARCHAR(6) , @midcount INT , @curcount INT , @customer_guid VARCHAR(36) , @objective_guid VARCHAR(36) DECLARE cursor1 CURSOR FOR SELECT newstaffid FROM bk1 WHERE flagstr=1 OPEN cursor1 FETCH NEXT FROM cursor1 INTO @powerstaffid WHILE @@fetch_status = 0 BEGIN DECLARE cursor3 CURSOR FOR SELECT oldstaffid FROM bk1 WHERE flagstr<>1 AND newstaffid=@powerstaffid OPEN cursor3 FETCH NEXT FROM cursor3 INTO @newstaffid WHILE @@FETCH_STATUS = 0 BEGIN SELECT TOP 1 @customer_guid = customer_guid FROM customer20111117 WHERE owner = @powerstaffid UPDATE customer20111117 SET owner = @newstaffid WHERE customer_guid = @customer_guid SELECT TOP 1 @objective_guid = objective_guid FROM objective20111117 WHERE customer_guid = @customer_guid AND objectivetype_id IN ( '17974B', '5172AF' ) AND objectivestatus = 'OPEN' UPDATE objective20111117 SET handleby_id = @newstaffid WHERE objective_guid = @objective_guid UPDATE oblist20111117 SET handleby_id = @newstaffid WHERE objective_guid = @objective_guid INSERT INTO tl ( newstaffid , powerstaffid , customer_guid , objective_guid ) VALUES ( @newstaffid , @powerstaffid , @customer_guid , @objective_guid ) FETCH NEXT FROM cursor3 INTO @newstaffid END CLOSE cursor3 DEALLOCATE cursor3 FETCH NEXT FROM cursor1 INTO @powerstaffid END CLOSE cursor1 DEALLOCATE cursor1
参考:
http://database.51cto.com/art/201009/224956.htm
作者: maco_wang 发布时间: 2011-11-17
SQL code
declare @powerstaffid varchar(6),@newstaffid varchar(6),@midcount int, @curcount int,@customer_guid varchar(36),@objective_guid varchar(36) declare cursor1 cursor for select newstaffid from bk1 where flagstr=1 open cursor1 fetch next from cursor1 into @powerstaffid while @@fetch_status=0 begin declare cursor3 cursor for select oldstaffid from bk1 where flagstr<>1 and newstaffid=@powerstaffid open cursor3 fetch next from cursor3 into @newstaffid while @@fetch_status=0 begin select top 1 @customer_guid= customer_guid from customer20111117 where owner=@powerstaffid update customer20111117 set owner=@newstaffid where customer_guid =@customer_guid select top 1 @objective_guid= objective_guid from objective20111117 where customer_guid =@customer_guid and objectivetype_id in('17974B','5172AF') and objectivestatus='OPEN' update objective20111117 set handleby_id=@newstaffid where objective_guid=@objective_guid update oblist20111117 set handleby_id=@newstaffid where objective_guid=@objective_guid insert into tl(newstaffid,powerstaffid,customer_guid,objective_guid) values(@newstaffid,@powerstaffid,@customer_guid,@objective_guid) fetch next from cursor3 into @newstaffid end close cursor3 deallocate cursor3 fetch next from cursor1 into @powerstaffid end close cursor1 deallocate cursor1
作者: ap0405140 发布时间: 2011-11-17
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28