Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple SCOPE_IDENTITY

0 views
Skip to first unread message

David C

unread,
Nov 19, 2009, 2:54:02 PM11/19/09
to
Can I use multiple SCOPE_IDENTITY() in the same stored procedure or is there
a better way?
I have a stored procedure that will create a new row in 2 tables and both
tables have identity columns.
The first INSERT will add a record to a People table and then set a variable
to the SCOPE_IDENTITY() for use in the INSERT of the 2nd table. Then the
2nd table will return the SCOPE_IDENTITY of the 2nd table. Thanks.

David


Andrew J. Kelly

unread,
Nov 19, 2009, 3:23:28 PM11/19/09
to
Yes you can check Scope_Identity() after each insert for the proper value.

--

Andrew J. Kelly SQL MVP
Solid Quality Mentors

"David C" <dlc...@lifetimeinc.com> wrote in message
news:#9uV$IVaKH...@TK2MSFTNGP04.phx.gbl...

Plamen Ratchev

unread,
Nov 19, 2009, 4:15:27 PM11/19/09
to
As alternative you can use the OUTPUT clause:
http://technet.microsoft.com/en-us/library/ms177564.aspx

--
Plamen Ratchev
http://www.SQLStudio.com

0 new messages