ALTER trigger [dbo].[Hr_CostHistory_Update] on [dbo].[Hr_CostHistory] after update
as
begin
declare @Batch varchar(50)
declare @ID varchar(50)
declare result_ID cursor for select A.ID from Cost_LabourDetail A inner join inserted B on A.SID=B.SID
open result_ID
fetch next from result_ID into @ID
while @@fetch_status=0
begin
declare result_Batch cursor for select Batch from Cost_Prouduce_Use where UseID=@ID
open result_Batch
fetch next from result_Batch into @Batch
while @@fetch_status=0
begin
exec AnalysisMadeMetCost @Batch
fetch next from result_Batch into @Batch
end
close result_Batch
deallocate result_Batch
fetch next from result_ID into @ID
end
close result_ID
deallocate result_ID
end
 如上面的代码,我在执行时总报
消息 16915,级别 16,状态 1,过程 AnalysisMadeMetCost,第 45 行
名为 'result_AnalysisMadeMetCost' 的游标已存在。 错误,,无论我怎么改result_AnalysisMadeMetCost的名称,总是报该名称已经存在错误

解决方案 »

  1.   

    你的代码没有'result_AnalysisMadeMetCost' .是AnalysisMadeMetCost存储里的问题吧.
      

  2.   

    先DROP cursor  result_AnalysisMadeMetCost 
      

  3.   


    是啊,AnalysisMadeMetCost里面也用到了触发器,总报AnalysisMadeMetCost里面的触发器名已经存在的错误
      

  4.   


    close result_ID
    deallocate result_ID
      

  5.   

    fetch next from result_ID into @ID
    --这句话的位置不对吧?
      

  6.   

    fetch next from result_ID into @ID 
    --这句话的位置不对吧?
    --应该放在下面一个 end 的后面才对吧?