Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Insert into Select @@identity

Author  Topic 

lcastillo83
Starting Member

2 Posts

Posted - 2010-10-19 : 12:42:44
Hi

I have one question related to the following sql:

Insert into T1 (date,desc) (select getdate(), textfield from t2)

this works good but I would like to get the identities generated from this instruction... eg. t2 have 5 records it will insert these 5 into T1... so I need the range of the 5 new records in T1 to generate a log in a T3 table which link log record... any ideas?

BR


LCastillo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-19 : 12:58:02
you need to use OUTPUT clause for that if you're using SQL 2005 or above. If sql 2000 or below, you need to use trigger for capturing generated ID values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -