Trigger with where clause

  • One week ago I wrote my first stored procedure. Since, that time I have made great progress normalizing a legacy system in SQL Express and have found it extremely interesting. As for the triggers, I have created a log table that has a trigger on it. Now, I can have the trigger fire if a certain field is updated. Is it possible to have the trigger fire, if the field is updated to a certain value.

    Thanks for any help

  • Sure ....

    IF (SELECT 1 FROM inserted WHERE yourField = 'yourTestValue')

    BEGIN

    -- your trigger code here

    END

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Sure ....

    IF EXISTS (SELECT 1 FROM inserted WHERE yourField = 'yourTestValue')

    BEGIN

    -- your trigger code here

    END

    OPPS... EDITED!! I forgot ot add the EXISTS keyword

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Genius.....

    Thanks man.....

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply