March 31, 2005 at 9:39 am
Greetings,
I am trying to get the identity value inserted into the table in the current scope and current session. There is an Instead of Insert trigger on the table, and I am not getting the identity column value when using scope_identity (). I have gone through BOL, and used the IDENT_CURRENT (table name) and getting the desired result. But somewhere in the user groups, I see that when using IDENT_CURRENT (), there is a possibility of getting a value which is out of the current scope and session. There are audit columns on the tables and using the instead of triggers to populate the audit columns when inserting the data. My question is what's the possibility of getting wrong value when using the IDENT_CURRENT (table name). Are there any better ways to workaround this problem? Also, why is the scope_identity () not returning any values when using instead of insert triggers??? Any comments and suggestion would be appreciated....
Thanks in advance.........
April 1, 2005 at 6:50 am
The trigger code is not in scope, hence scope_identity() will not pick it up.
Maybe @@identity will do it for you - unless you have other identity inserts in the trigger.
Its in the bol under scope_identity() but you need to read carefully as the example they give is the opposite situation where they do *not* want to get the identity generated in the trigger.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply