all groups > sql server programming > october 2003 >
You're in the

sql server programming

group:

Identity


Identity Jonas Mandahl Pedersen
10/29/2003 11:35:55 PM
sql server programming: I have two cursors insertíng quite often into a table with identity on the
ID.
Can anyone confirm that by calling select @@IDENTITY AS 'Identity' i get the
last Id for the record inserted by a specific cursor.

ex listed in order of execution:
1) Cursor1 : insert blablabla
2) Cursor2 : insert buhbuhbuh
3) Cursor1: select @@IDENTITY AS 'Identity'
4) Cursor2: select @@IDENTITY AS 'Identity'

Then intension is that 3) should get the ID from call 1) and not call 2).
And 4) from 2).
Jonas

Re: Identity David Portas
10/30/2003 11:10:34 AM
No. @@IDENTITY gives the last inserted value for any table in the current
connection. SCOPE_IDENTITY gives the last value within the current scope.

But your question suggests your code needs a redesign. Why use two cursors
to insert rows? Use a single, set-based INSERT statement instead. This
should also avoid the need to retrieve the IDENTITY value at all.

Post your DDL and code if you need help with the set-based solution.

--
David Portas
------------
Please reply only to the newsgroup
--

AddThis Social Bookmark Button