• Bradley Deem (5/13/2010)


    Toreador (5/13/2010)


    Interesting - it never occurred to me that the identity values wouldn't be available in the inserted table!

    So how would you get the identity values of the rows you'd just inserted?

    Change the trigger as follows. Of course, I'm not sure how you would capture the output result set, save using the temp table method as previously mentioned, but then the caller would have to know to look for that temp table.

    CREATE TRIGGER TestTrigger ON TestTable

    INSTEAD OF INSERT

    AS

    INSERT TestTable (string)

    OUTPUT INSERTED.*

    SELECT CASE WHEN string = 'TestString' THEN string ELSE 'Stub' END

    FROM inserted

    Excellent question, I definitely learned something today!

    Wow, I can't decide whether I'm amazed at the ingenouity in making an INSERT statement do that or appalled that an INSERT statement can be made to do. Probably both. Bradley, that's a beautiful piece of code, excuse me now, I have to go disinfect my dev server with bleach and thermite.

    Excellent QOTD.

    -DW