trigger code

  • I have a table called [dbo].[timedes] with 5 columns (id, lastname, firstname, status, modifieddate)

    I want to update modifieddate to today’s date when every there is a modification to any field except the status field

    So I created a trigger

    create TRIGGER [trigdate] ON [dbo].[timedes]

    AFTER UPDATE AS

    BEGIN

    SET NOCOUNT ON;

    if not update (status)

    begin

    UPDATE dbo.timedes

    SET dbo.timedes.modifieydate = GETDATE()

    from inserted

    WHERE inserted.id = timedes.id ;

    end ;

    end

    but its not updating the modifieydate even when lastname or firstname changes and really need help

  • mesql (10/7/2008)


    I have a table called [dbo].[timedes] with 5 columns (id, lastname, firstname, status, modifieddate)

    I want to update modifieddate to today’s date when every there is a modification to any field except the status field

    So I created a trigger

    create TRIGGER [trigdate] ON [dbo].[timedes]

    AFTER UPDATE AS

    BEGIN

    SET NOCOUNT ON;

    if not update (status)

    begin

    UPDATE dbo.timedes

    SET dbo.timedes.modifieydate = GETDATE()

    from inserted

    WHERE inserted.id = timedes.id ;

    end ;

    end

    but its not updating the modifieydate even when lastname or firstname changes and really need help

    Try this:

    create TRIGGER [trigdate] ON [dbo].[timedes]

    AFTER UPDATE AS

    BEGIN

    SET NOCOUNT ON;

    if (update (lastname) or update(firstname))

    begin

    UPDATE dbo.timedes

    SET dbo.timedes.modifieydate = GETDATE()

    from inserted

    WHERE inserted.id = timedes.id ;

    end ;

    end

    😎

  • I think Lynn probably has an answer that works, so I'll just say that I'm glad the trigger will is written to handle sets. That's rare in these forums, it seems.

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

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