Getting Identity Values for group of inserts | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Getting Identity Values for group of inserts

Hi all, I am using the following sql statements to select from a table and insert into destination table. SELECT * INTO TEMP_TABLE
FROM TABLE1 How can I get the identity values for all the records that are inserted. Thanks and Regards,
Ram Kumar N D

SELECT identitycol

Frank Kalis
Microsoft SQL Server MVP
Heute schon gebloggt?
Ich unterst�tze PASS Deutschland e.V.
The temp table is already having some rows. so i need to get the identity values for the latest select query thet i had executed
After insert do this:
select @@identity
this will give the last inserted identity value.
Determine the MAX(identitycol) before doing the SELECT INTO. All values greater than that, you have inserted vai SELECT INTO. [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br /<a target="_blank" href=></a><br />Heute schon gebloggt?<a target="_blank" href=></a><br />Ich unterst�tze PASS Deutschland e.V. <a target="_blank" href=></a>)
If you run this SELECT * INTO TEMP_TABLE
FROM TABLE1 then the new table TEMP_TABLE is created with the values in TABLE1 and values are not appended. Then how do you expect it having previous data? To have previous data, you should have run Insert into TEMP_TABLE(columns)
SELECT columns FROM TABLE1 Then do what Frank suggested
Madhivanan Failing to plan is Planning to fail
Yes, nice catch Madhivanan.<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ /><br />