Error Message:
Msg 330, Level 16, State 1, Line 6
The target ‘%.*ls’ of the OUTPUT INTO clause cannot be a view or common table expression.
Severity level:
16.
Description:
This error message appears when you try to insert rows via the OUTPUT INTO clause into a common table expression.
Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.
Resolution:
Errors of the Severity Level 15 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. A common table expression cannot be the target for the OUTPUT INTO clause.
Versions:
This error message was introduced with SQL Server 2005.
Example(s):
USE Northwind;
GO
DECLARE @t table
(
OrderID int
);
;WITH myCte (OrderID)
AS (SELECT OrderID
FROM @t)
UPDATE TOP (10) Orders
SET OrderDate = DATEADD(DAY, 1, OrderDate)
OUTPUT INSERTED.OrderID
INTO myCte;
SELECT *
FROM @t;
Remarks:
There are other alternatives available, such as temporary table or table variables.