General discussion

  • Creator
    Topic
  • #2194168

    Why does this Trigger go off?

    Locked

    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.

All Comments

  • Author
    Replies
    • #3111882

      Reply To: Why does this Trigger go off?

      by j.lupo ·

      In reply to Why does this Trigger go off?

      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.

    • #3279392

      Reply To: Why does this Trigger go off?

      by tony hopkinson ·

      In reply to Why does this Trigger go off?

      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))

Viewing 1 reply thread