All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

Error Message:
Msg 205, Level 16, State 1, Line 1
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

Severity level:
16.

Description:
This error message appears when you try to run a UNION, INTERSECT or EXCEPT query that has not an equal number of expressions in their SELECT list sections.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Errors of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. All SELECT parts of a combined query using a UNION, INTERSECT, or EXCEPT operator must have an equal number of expressions.

Versions:
All versions of SQL Server.

Example(s):
SELECT 1
UNION ALL
SELECT 1, 2

Remarks:
In the above example we try to combine two queries using a UNION ALL operator. Because each SELECT list has a different number of expressions, the error is raised.




Array

No comments yet... Be the first to leave a reply!