sqlserver2008中游标问题,执行后一个多小时都不显示结果,13000条数据,请各位大神帮忙看下!急!!!
alter proc youbiao_1
as
begin
declare @id int
declare demo cursor for select resinterview.resInterviewId from resource,resinterview where resource.email=resinterview.email and resource.email!='' and resinterview.email!=''
open demo
fetch demo into @id
while @@FETCH_STATUS=0
begin
update resource set interviewid=@id where resourceId=(select resourceId from resinterview where resInterviewId=@id)
end
close demo
end
------解决方案--------------------
标准游标写法:
SQL code
declare @rid int
declare @times int
declare fetch_id cursor for select RP_ID, times from RP_RegulationPlan --声明游标
open fetch_id--打开
fetch fetch_id into @rid,@times
while @@fetch_status=0
begin
--这里写你要执行的语句
fetch next from fetch_id into @rid,@times
end
close fetch_id--关闭
deallocate fetch_id--删除