How to stop events from firing for the same thing twice...
I have a trigger that fires events to SSNS on INSERT and UPDATE to my table.
It all works fine, execpt that in my application that uses this table, there
is code in there inserts to the table and then immediately fires an update.
This results in 2 events being fired almost at the same time and so 2 notifications
What I want to do is to check that if the record is already in the "pending"
events list before my trigger goes and fires an event for it - but I can't
figure out how to do it. Heres my attempt, which doesn't work:
CREATE TRIGGER NewRecordTrigger
FOR INSERT, UPDATE
DECLARE @eventBatchId BIGINT
DECLARE @providerName NVARCHAR(255)
DECLARE @ID INT
DECLARE @NSINstalled char(1)
Select @NSInstalled = dbo.IsSSNSInstalled()
IF (@NSInstalled = 'Y')
SELECT @providerName = N'NewRecordAddedSPProvider'
SELECT @ID = ID from inserted
-- This is the line I would have expetced to not add the same
event more than once!
If NOT Exists (Select * from EntropyAlerts.NSCurrentNewRecordAddedEvents
where ModuleCode = 'SITE_INC' and RecordID = @IncidentID)
EXEC [EntropyAlerts].[NSEventBeginBatchNewRecordAdded] @providerName, @eventBatchId
Can anyone explain why this doesn't work? I'm thinking its related to the
fact that the triggers fire almost at the same time, so they both execute
the check at the same, and then both add the event at the same time. I tried
wrapping some transactions in there, but to no avail.
|<Prev in Thread]
||[Next in Thread>|
- How to stop events from firing for the same thing twice...,
matt roberts <=