游标 处女作

 

  由于触发器的原因,所以更新数据的时候经常不能使用直接update来修复数据。所以试着去用游标来更新

 

 

代码
declare upduser scroll cursor
for
select aopp_userid from aopportunity
where aopp_userid <> aopp_createdby
and aopp_status ='ccfollowup'
and aopp_deleted is null
and aopp_userid is not null
for update

open upduser

declare @aopp_userid int
fetch from upduser into @aopp_userid
while @@fetch_status = 0
begin
if @aopp_userid is not null
--print @aopp_userid
update aopportunity set aopp_createdby = @aopp_userid,aopp_contractcounselor = @aopp_userid
where current of upduser
fetch from upduser into @aopp_userid
end
close upduser
deallocate upduser

 

 

 

 

posted @ 2010-01-05 19:07  nick_lsf  阅读(207)  评论(0编辑  收藏  举报