Is it possible to display which rows I did inserted via this query:
INSERT INTO dbo.Table (Col1, Col2, Col2)
(SELECT
Col1,
Col2,
'Something modified',
FROM dbo.Table
WHERE Col10 = 66)
It is important to obtain whole new row with it's PrimaryKey value, etc., not only Col1, Col2, Col3
The
OUTPUT
clause is your friend now:You can insert the result of the
OUTPUT
by specifying the destination table with theINTO
clause or by wrapping the query as a subquery:INTO
clauseThis is useful, when you want to insert the same data into two tables. You can always list the required fileds in the OUTPUT clause (inserted.Col1, inserted.Col2)
SUBQUERY
This is useful, when you want to join the OUTPUT to another tables or you want to make calculations (like summing or counting values) and insert those results into another table.