Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server 7 - Need the value of an identity just inserted

Status
Not open for further replies.

Brett123

Programmer
May 15, 2000
4
US
In a web-based app. designed using Bluestone's Sapphire/Web (Yes, I know...) I enter a new row to a table with its key automatically inserted via the identity_insert option in SQL Server.&nbsp;&nbsp;Immediately after this row is inserted, I need to know what value was just inserted (I don't feel that just taking the largest value in the table is safe enough).&nbsp;&nbsp;Is there a way to return the value inserted when identity_insert is used?<br><br>Thanks in advance, <br>Brett
 
From Books On Line: <br><br><i>After an INSERT, SELECT INTO, or bulk copy statement completes, <b>@@IDENTITY</b> contains the last identity value generated by the statement. If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL. If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns the last identity value generated.</i><br><br>i.e. immediately after the insert if you <FONT FACE=monospace>SELECT @the_id = @@IDENTITY</font> you will get back the value. <p> <br><a href=mailto: > </a><br><a href= home</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top