Help with update trigger

  • Ok, this is probably easier than I'm making it out to be, but is there a way to write a trigger on an update of one field. What I mean is, if I write a trigger on update, that means anytime that table is updated, the trigger will fire. I need my trigger to only run when a certain field is updated. What I'm tring to do:

    If APINSP.COMPDTTM is updated, at that value it's updated to, add 180 days to it and then update APBLDG.EXPTDTTM to the new value; however, if that record is updated and APINSP.COMPDTTM doesn't get updated, than don't update APBLDG.EXPTDTTM.

    Thanks,

    Jordon

  • You can use the internal tables INSERTED and the DELETED and find out what to do.

    Thanks,

    Nikul

  • Would a computed column work better?

    CREATE TABLE tempdb.dbo.ApInsp (CompDttm DATETIME NOT NULL, ExpDttm AS DATEADD(DAY, 180, CompDttm));

    INSERT tempdb.dbo.ApInsp (CompDttm) VALUES ('20090314');

    SELECT CompDttm, ExpDttm FROM tempdb.dbo.ApInsp;

    DROP TABLE tempdb.dbo.ApInsp;

    Paul

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

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