General discussion

Locked

Why does this Trigger go off?

By rheal.dugas ·
I have created a SQL trigger that should only work if both fields are updated. Can someone tell me why when ony one field is uptated that this trigger goes off.
Thank You

CREATE TRIGGER send_update_request

on dbo.ONSA_NSS

FOR UPDATE

AS

--- Send a Update request to the owning ONSA/AGENT

Declare @ID NVARCHAR (4000)
Declare @subject NVARCHAR (100)
Declare @too NVARCHAR (100)

IF NOT UPDATE (requestsent) AND NOT UPDATE (sentagaintimes)

BEGIN

RETURN

END

SELECT @too = (SELECT updateemail FROM Inserted)
SELECT @subject = (SELECT 'REQUEST LOG UPDATE' FROM Inserted)
SELECT @ID = (SELECT 'You Log Number ' +
Log_ID +'
'+ 'has not been update in 12 days.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by j.lupo In reply to Why does this Trigger go ...

I wouldn't do it this way. Using negative logic here can cause lots of problems.

if update() and update() then
begin
select ...
end
return

This way you only do the statements IF BOTH fields have been updated.

Just a suggestion and I only scanned your issue. Please let us know how it goes.

Collapse -

by Tony Hopkinson In reply to Why does this Trigger go ...

algebraic short cut
NOT UPDATE (requestsent) is true ,so 2nd condition is never evaluated
reverse it like previous poster said or
change to
IF NOT (UPDATE (requestsent) AND UPDATE (sentagaintimes))

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums