我有这个触发器
CREATE TRIGGER CHECKINGMAXQTYDAYSVACANCY ON TDINCI AFTER INSERT AS DECLARE @incidentCode int,@dateStart datetime,@dateEnd datetime,@daysAccumulated int,@maxDaysAvailable int set @daysAccumulated = 0; select @incidentCode = CO_INCI from inserted; select @maxDaysAvailable = IN_DIAS_GANA from TCINCI where CO_INCI = @incidentCode; declare detailsCursor CURSOR FOR select FE_INIC,FE_FINA from TDINCI where CO_INCI = @incidentCode; open detailsCursor; if CURSOR_STATUS('variable','detailsCursor') >= 0 begin fetch next from detailsCursor into @dateStart,@dateEnd; while @@FETCH_STATUS = 0 begin set @daysAccumulated = @daysAccumulated + (DATEDIFF(DAY,@dateStart,@dateEnd) + 1); fetch next from detailsCursor into @dateStart,@dateEnd; end close detailsCursor; deallocate detailsCursor; end IF(@maxDaysAvailable > @daysAccumulated) BEGIN RAISERROR ('No se pueden ingresar mas dias de los programados en la cabecera de incidencias.',16,1); ROLLBACK TRANSACTION; RETURN END GO
当我做一个插入表TDINCI
INSERT INTO TDINCI VALUES (1,'20150101','20150115','2015-2015')
我收到一个错误:
A cursor with the name ‘detailsCursor’ already exists.
我打开
open detailsCursor;
并关闭光标.
close detailsCursor; deallocate detailsCursor;
也许有一些我没有管理的游标的范围?提前致谢.