Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    18

    Question Unanswered: Update inserted value

    Hi,
    I have a trigger which is meant to update a value on an INSERT.
    To be clear, when an INSERT occurs, this trigger is fired :

    CREATE TRIGGER INS_TABLE
    ON TABLE1
    INSTEAD OF INSERT AS

    DECLARE @VALUE DATETIME

    select @VALUE = GETDATE()
    UPDATE INSERTED SET col = @VALUE

    But it is not possible to update the inserted table.
    Do you know how to do that ?
    Thanks

  2. #2
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    so you are trying to intercept the insert and change a value but allow the transaction to occur right?

    Try this:untested

    create trigger foo on table
    for
    insert
    as
    update table set value = value+1 where ikey in (select ikey from inserted)

    This assume you have a PK (I called it ikey) and whatever function you are wanting to do (I did value+1)

    HTH - if I am off base, please elaborate
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  3. #3
    Join Date
    Jul 2003
    Posts
    18
    It seems to work.

    Tnahks a lot !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •