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

Posted on : 27-04-2012 | By : Devi Prasad | In : SQL Errors

Share:

0


Error:

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.

Reason:
The select statements in the clause do not have the same number of columns.

Fix:
Make sure that all the starements using UNION, INTERSECT or EXCEPT operator have same number of expressions(columns).
Use column names instead of using * in the select list.

Sample example code

Before:

SELECT 1
UNION
SELECT 2,3

After:

SELECT 1,NULL
UNION
SELECT 2,3
(Visited 3,995 times, 1 visits today)



References : Devi Prasad (sqlserverlearner.com)

Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.


Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.




Write a comment



Tags: , ,