I have a table in which I need to copy certain rows. I can get IDs of new rows like this:
DECLARE @IDs TABLE (ID int)
INSERT T (name, address)
OUTPUT INSERTED.TID INTO @ids
SELECT name, address
FROM T
But what I would like to have is 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?
P.S. I'm not doing this programmaticaly, because it has to be done by a stored procedure.