Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ADO 2.0 and SQL Server
Message
From
03/02/1999 14:28:39
 
 
To
26/01/1999 02:44:42
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00178333
Message ID:
00183567
Views:
13
>DECLARE @li_Index INTEGER
>
>INSERT INTO tab_MyTable
>   (Field_1,
>    Field_2)
>VALUES
>   (@Field_1,
>    @Field_2)
>
>SELECT @li_Index = @@IDENTITY
>
>Now the SQL variable @li_Index value is set to the identity value used to insert the record into the table tab_MyTable. In fact, the SQL global variable @@IDENTITY always contains the last inserted identity for the session (do not be afraid of concurrent accesses).

There's only one thing to be aware of. If tab_MyTable has an insert trigger that inserts a row into another table, say tab_YourTable, AND tab_YourTable also has a column with the identity property, @@IDENTITY will contain the identity value that was used by tab_YourTable, NOT tab_MyTable.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform