title: How to copy rows with SQL and get new and old IDs as result?
body: <p>I have a table in which I need to copy certain rows. I can get IDs of new rows like this:</p>
  
  <pre><code>DECLARE @IDs TABLE (ID int)
  INSERT T (name, address)
  OUTPUT INSERTED.TID INTO @ids
      SELECT name, address
      FROM T
  </code></pre>
  
  <p>But what I would like to have is something like this:</p>
  
  <pre><code>DECLARE @IDs TABLE (oldID int, newID int)
  INSERT T (name, address)
  OUTPUT T.ID, INSERTED.TID INTO @ids
      SELECT name, address
      FROM T
  </code></pre>
  
  <p>Can this be done with SQL Server?</p>
  
  <p>P.S. I'm not doing this programmaticaly, because it has to be done by a stored procedure.</p>