Is there a way to retrieve all the keys of the newly inserted records when using an INSERT INTO ... SELECT FROM query?
DECLARE @MyVar TABLE ( ID int ) INSERT INTO dbo.TargetTable OUTPUT INSERTED.ID INTO @MyVar SELECT * FROM dbo.SourceTable SELECT * FROM @MyVar