• 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) A socialist is someone who will give you the shirt off *someone else's* back.