• wendy elizabeth (2/6/2013)


    USE [DEV]

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TRIGGER [dbo].[update_trigger]ON [dbo].[Transaction_Tracking]

    AFTER UPDATE

    AS

    BEGIN

    INSERT

    INTO [dbo].[eRPT_Transaction_Audit]

    ( Package_ID, Received_Date, Start_Date,Operation, TriggerTable)

    SELECT i.Package_ID, i.Received_Date, i.Start_Date,'U', 'I'

    FROM inserted i

    INNER JOIN deleted d ON i.Track_ID=d.Track_ID

    WHERE (SUBSTRING(i.Package_ID,1,3) = 'RVW' or SUBSTRING(d.Package_ID,1,3) = 'RVW')

    and i.Start_Date<>d.Start_Date

    ;

    END

    ;

    GO

    That looks like it should work. I would however recommend that you not use such a generic name for your trigger. If you name your trigger "update_trigger" you can't have another trigger with that name in the database. A common naming convention for this would be something like tr_Transaction_Tracking_Update. That identifies the trigger clearly and prevents naming collisions with other triggers on other tables.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/