Hi,
Here's how to do it (changes in bold):
CREATE TRIGGER [dbo].[INSERT_IM_ServiceRequest_Hx] ON [dbo].[IM_ServiceRequest] AFTER INSERT, UPDATE
AS
BEGIN
DECLARE @Action AS CHAR(1) = 'I';
IF EXISTS (SELECT 1 FROM INSERTED) AND EXISTS (SELECT 1 from DELETED)
SET @Action = 'U';
IF (@Action = 'I')
BEGIN
INSERT INTO IM_ServiceRequest_Hx
SELECT * FROM IM_ServiceRequest
PRINT 'AFTER INSERT Trigger fired.'
END
IF (@Action = 'U')
BEGIN
END
END
-------------------------------------------------------------------------------------
Added information:
1. Simplified trigger syntax:
CREATE TRIGGER trigger_name
ON { table | view }
{ FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
2. There are 2 special tables in trigger statements:
inserted and
deleted. Inserted table stores copies of the affected rows after INSERT and UPDATE. Deleted table stores copies of the affected rows after DELETE and UPDATE.
AFTER INSERT: 1 or more records in INSERT table, 0 records in DELETE table.
AFTER UPDATE: 1 or more records in INSERT table, 1 or more records in DELETE table.
AFTER DELETE: 0 records in INSERT table, 1 or more records in DELETE table.
Knowing this, you can determine certain event: AFTER INSERT, UPDATE or DELETE.