試試這個解決方案 -
ALTER TRIGGER [LabourAPI].[trg_IOIU_Employee]
ON [LabourAPI].[Employee]
INSTEAD OF INSERT, UPDATE
AS BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
DECLARE
@EmployeeID INT
, @PersonID INT
, @TabelNumber VARCHAR(6)
, @DepartmentUID UNIQUEIDENTIFIER
, @PositionID INT
, @DateIn DATETIME
, @DateOut DATETIME
, @IsMainWorkPlace BIT
, @DatePension DATETIME
, @IsLabourUnionMember BIT
, @FiringReasonID INT
DECLARE cur CURSOR LOCAL READ_ONLY FAST_FORWARD FOR
SELECT
EmployeeID
, PersonID
, TabelNumber
, DepartmentUID
, PositionID
, DateIn
, DateOut
, IsMainWorkPlace
, DatePension
, IsLabourUnionMember
, FiringReasonID
FROM INSERTED
OPEN cur
FETCH NEXT FROM cur INTO
@EmployeeID
, @PersonID
, @TabelNumber
, @DepartmentUID
, @PositionID
, @DateIn
, @DateOut
, @IsMainWorkPlace
, @DatePension
, @IsLabourUnionMember
, @FiringReasonID
WHILE @@FETCH_STATUS = 0 BEGIN
SELECT
@PersonID
, @TabelNumber
, @DepartmentUID
, @PositionID
, @DateIn
, @DateOut
, @IsMainWorkPlace
, @DatePension
, @IsLabourUnionMember
, @FiringReasonID
FETCH NEXT FROM employee INTO
@EmployeeID
, @PersonID
, @TabelNumber
, @DepartmentUID
, @PositionID
, @DateIn
, @DateOut
, @IsMainWorkPlace
, @DatePension
, @IsLabourUnionMember
, @FiringReasonID
END
CLOSE cur
DEALLOCATE cur
END