• CELKO (12/27/2012)


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

    The term for this is "union compatible" and it means that both tables in a set operation have to have the same number of columns and those columns have to match by data type and by position.

    Further more, the result of a set operation is a table whose columns have no names. This means that you need to write an AS clause to name them.

    (<table expr #1>

    [UNION | INTERSECT | EXCEPT] [ALL]

    <table expr #2>)

    [AS] <table name> (<column list>)

    No you don't for SQL Server. The first query provides all the column names.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".