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)
 get inserted id's

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2014-02-07 : 04:16:57
if i run

insert into images(date,picture)
select date from #t2

how can I get a list of the inserted id's?

(the @@identity of each record inserted?)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-07 : 05:17:00
use the OUTPUT clause http://technet.microsoft.com/en-us/library/ms177564.aspx

create table #id ( id int );

insert into images(date,picture)
output inserted.id into #id (id)
select date from #t2



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2014-02-09 : 01:51:41
thanks i need to debug this more

if i do the following as a test

create table #id ( id int );

insert into images(date,picture)
select date,picture, from images where dateinserted>'20140209'
output inserted.id into #id (id)

select * from #id

i get an error Incorrect syntax near 'output'.

Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2014-02-09 : 02:07:26
i figured this out - output has to be before the values inserted
thanks for your help
Go to Top of Page
   

- Advertisement -