I have a table in which I need to copy specific rows. I can get the new line IDs as follows:
DECLARE @IDs TABLE (ID int)
INSERT T (name, address)
OUTPUT INSERTED.TID INTO @ids
SELECT name, address
FROM T
But I would like to have something like this:
DECLARE @IDs TABLE (oldID int, newID int)
INSERT T (name, address)
OUTPUT T.ID, INSERTED.TID INTO @ids
SELECT name, address
FROM T
Can this be done with SQL Server?
PS I do not do this programmatically because it must be done using a stored procedure.
source
share