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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 concat insert statements and return identity valu

Author  Topic 

nirnir2
Starting Member

20 Posts

Posted - 2014-05-26 : 15:02:45
i need to insert multiple rows into table and return all new identity values .
I want to do it in one call to the sqlserver .
How can I concat the insert statements into one string and return all identity values

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-05-26 : 15:39:52
one way:
- construct an xml string to represent the new rows.
- pass the xml to a stored proc
- sp will parse the rows into a staging (temp) table.
- merge the data into your real table
- select what you want from the real table JOINed to your staging table to get back the identities associated with logical data.

Be One with the Optimizer
TG
Go to Top of Page

nirnir2
Starting Member

20 Posts

Posted - 2014-05-26 : 16:35:06
Thanks
but I found something much simple

INSERT INTO test (a,b,c)
OUTPUT inserted.recid
VALUES
(1,'somename','sometitle'),
(2,'somename','sometitle'),
(3,'somename','sometitle'),
(4,'somename','sometitle')
Go to Top of Page
   

- Advertisement -