I am quite new to writing SQL triggers and I had one working for a while now as desired however now I would like to add a where clause to the trigger so that it only fires if a certain condition is met.
In this particular scenario I want to check and see if ContextDN like '%FA 2012%' and if so then have the trigger fire. Here is my current trigger:
CREATE TRIGGER [dbo].[setAsMoodle]
ON [dbo].[LMS_Section]
For Insert
As
INSERT INTO [dbo].[CUS_LmsSection_LmsProxy] (LMSSectionID, LMSProxyID, LMSSectionCtxDN)
select SectionID , 'DEE76E47-25E6-459B-9D38-1BCAFA44077A', ContextDN from inserted
Any suggestions on how to go about doing this?
Just put the where on the end of your insert statement
The trigger will always fire, but only the rows matching the condition get inserted.
This is important as the trigger may fire for multiple rows at once for a batch insert so you wouldn’t be able to selectively run it.