I only want to update the comment if a description for the event is found in the TagDescLookup Table. If the Tag isn’t in the Lookup table then don’t change the existing Value for the comment column. The current trigger will update the comment column with the correct value unless the value isn't found in the lookup table, it sets comment to Null. I'm using SQL server 2017.
USE [AwxLogger]
GO
/****** Object: Trigger [dbo].[TagDescTrigger] Script Date: 14/03/2019 16:47:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[TagDescTrigger]
ON [dbo].[EventLog]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON
UPDATE [dbo].[EventLog]
SET Comment =
(
SELECT [Description] FROM TagDescLookup
WHERE Tag = I.NameOfParameter
)
FROM [dbo].[EventLog] AS E
JOIN INSERTED AS I
ON E.NameOfParameter = I.NameOfParameter
END
TagDescLookup Table
ID int NOT NULL PRIMARY KEY IDENTITY (1,1)
Tag nvarchar(MAX) NOT NULL
Description nvarchar(MAX)