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
[解决办法]
标准游标写法:
declare @rid intdeclare @times intdeclare fetch_id cursor for select RP_ID, times from RP_RegulationPlan --声明游标open fetch_id--打开fetch fetch_id into @rid,@timeswhile @@fetch_status=0begin --这里写你要执行的语句 fetch next from fetch_id into @rid,@timesendclose fetch_id--关闭deallocate fetch_id--删除