Home Forums SQL Server 2008 SQL Server 2008 - General Update a date field with a Trigger when a transaction is posted to another table RE: Update a date field with a Trigger when a transaction is posted to another table

  • David Burrows (5/11/2014)


    In that case use Eirikur's trigger although you could simplify it to

    CREATE TRIGGER trg_LastSaleDate ON dbo.Transheaders

    AFTER INSERT, UPDATE

    AS

    IF UPDATE(TradingDate)

    BEGIN

    UPDATE c

    SET c.ZLastDate = i.TradingDate

    FROM inserted i

    JOIN dbo.Customers c ON c.UniqueID = i.UniqueID

    END

    Slight difference in the logic, this code will do an update every time, even if the existing value is equal to the update value.

    😎