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

  • Eirikur Eiriksson (5/11/2014)


    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.

    😎

    True and the only reason to restrict the update would be to reduce logging or prevent the regression of the date (ie update only if the date is greater than the current value)

    Far away is close at hand in the images of elsewhere.
    Anon.