Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
is it possible to Retrieve Identity Values When Inserting Multiple RowsI have searched high and low and have not been able to find anything. is there a sort of SCOPE_IDENTITY() temp table?Thanks
Skorch
Constraint Violating Yak Guru
300 Posts
Posted - 2009-01-21 : 18:43:39
Are you possibly referring to @@IDENTITY?
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts
Posted - 2009-01-21 : 19:01:27
Here is an example of using the OUTPUT clause for that:
create table #t ( id int identity primary key clustered, x int not null)insert into #t ( x )output inserted.id, inserted.xselect xfrom ( -- test data select x = 1 union all select x = 4 union all select x = 7 ) aorder by xdrop table #tResults:id x----------- -----------1 12 43 7(3 row(s) affected)