Trigger SQL to UPDATE Only row being Updated

  • hi,

     

    i need help about sql update trigger.

    i want to update date field when status changed. but the trigger that i write update all date coloumn.

    thanks for help.

    CREATE TRIGGER trgu_TABLE_A ON lv_order AFTER UPDATE, INSERT

    AS if update(ord_statusID)

    BEGIN

     UPDATE lv_order SET ord_ExpShipDate=getdate()

      FROM inserted i INNER JOIN lv_order c ON i.ord_ID = c.ord_ID

    END

  • If you were to issue an UPDATE lv_order SET ord_statusID = 1 WHERE ord_id = (some valid ID), your trigger will correctly update the ord_ExpShipDate column for only the one Ord_ID row that you specify.  You have written it correctly.  The only time it will update multiple rows is if you are updating the statusID on multiple rows or inserting multiple rows at once.  If you are still having problems, can you give more detail as to what exactly is happening.  It would be helpful if you could post some sample data and the update or insert statement that you think is causing all rows to be updated. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

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

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