Trigger Question

  • I would like to create an After trigger that sets a flag value in a record if another field in that record is updated. My question is how do I capture the records that received updates? If I have

    CREATE TRIGGER trg_setflag ON Table1 FOR UPDATE

    AS

    BEGIN

       UPDATE Table1

          SET flag = 'Y'  "pseudocode now" when date1 has been changed FROM inserted

    END

    Go

    set flag to Y on those records where the date has been updated. The date in several records may be updated and several corresponding flags must be updated to Y

    Thanks for any help you can provide

  • Try this

    If Update(Date1)

    BEGIN

    UPDATE Table SET Flag = 'Y'

    FROM Table A INNER JOIN Inserted I ON A.PrimaryKey = I.PrimaryKey

    END


    Kindest Regards,

  • Thank you for the reply.

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

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