Skip to content
Advertisement

unable to create view because of different number of columns from different tables

This is error statement in SSMS “All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.” why can’t i create view like this?

Advertisement

Answer

All the sub queries need to have the same number of columns, with the same names and datatypes, and in the same order. If some subqueries/tables don’t have columns that other subqueries/tables do, you still need to define those columns.

For example, Lossrun.LandingAthensDailyClaim doesn’t have a ClientName column defined in its subquery. But based on the view definition and other subqueries, we still need to add it. We can use NULL for the value in this case.

Taking your view definition, I came up with the following query:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement