3 ms·
The OUTPUT clause in MSSQL doesn't require a CTE, and can be used with INSERT, DELETE and MERGE in addition to UPDATE. Likewise, your example can also be done
by pradocchia 13y ago
The OUTPUT clause in MSSQL doesn't require a CTE, and can be used with INSERT, DELETE and MERGE in addition to UPDATE.
Likewise, your example can also be done with derived tables, which predate CTEs in MSSQL:
UPDATE a SET col2 = 10
OUTPUT INSERTED.key1 INTO @local_table (key1)
FROM (SELECT TOP (1) * FROM table1 ORDER BY col1) a