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
 identity column issue

Author  Topic 

jac2375
Starting Member

1 Post

Posted - 2012-01-16 : 02:57:35
I am using SQL Server 2008 to create a procedure.

I am using the following sql statement to insert into a audit table

insert into Listuser
(
UserID,
ListID,
AuditCreated
)
select
UserID,
ListID,
GETDATE()
from ListUser where Surname='surname'

I am using scope_identity() to get the identity column from the listuser table and insert the identity column to another logs table

If the select statement contains more than 1 value, how to get the identity value of both columns and insert into logs table?
quote:

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-16 : 03:26:07
use the Output Clause
http://msdn.microsoft.com/en-us/library/ms177564.aspx


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-16 : 03:36:36
see an example here

http://visakhm.blogspot.com/2011/08/multiple-table-insertion-using-single.html

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

Go to Top of Page
   

- Advertisement -