Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Oxfordshire
    Posts
    18

    Wink Unanswered: Conditional Trigger

    I am trying to write a trigger that will only fire when certain fields are updated. I can't seem to find any threads that relate to this issue. Below is the trigger syntax. Any info would be great. Thx

    CREATE TRIGGER tr_feedback_date ON Calls
    FOR UPDATE AS
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    if update (feedback) or update (analyst) or update (coordinator) or update (technical) or update (fixtime)
    or update (phonewait) or update (resp)
    UPDATE hold_complete
    set hold_complete.feedbackdt = getdate()
    from inserted with (nolock)
    where hold_complete.fkey = inserted.callid

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The create trigger statement can take an IF UPDATE ( column ) clause. You can read about it in Books Online.

    Another option it to compare the values in the INSERTED table to the values in the DELETED table. Since updates involve both insertions and deletions, your affected record will exist in both and you can compare the differences based on the primary key.

    blindman

  3. #3
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621

    Re: Conditional Trigger

    Also, there is very useful function COLUMNS_UPDATED() which you can use in trigger for checking what fields were updated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •