Aaron,
You have to supply the same number of expressions in both select
statements. If one table has less columns than the other you can pad it
out by selecting empty strings:
select a, b, c, '', '', '', '' from tbl_1
union
select x, y, z, aa, bb, cc, dd from tbl_2
The other thing to remember is that the selected columns have to be of the
same data type (or at least one that can be converted implicitly) e.g if
column a has a char datatype but x is an integer then the select won't work
unless a convert statement is used.
Christine Carter
DBA
PricewaterhouseCoopers
"aaron"
<[Email Address Removed] To: "LazyDBA.com Discussion" <[Email Address Removed]
cc:
30/05/2003 16:03 Subject: Combine two statements ...
How can I combine two select statements that do not have an equal number of
expressions???
Select a, b, c from tbl_1
Union
Select x, y, z, aa, bb, cc, dd from tbl_2
Then.. The desired results would be:
A, b, c, x, y, z, aa, bb, cc, dd
:)
---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed] End of message text --------------------
This e-mail is sent by the above named in their
individual, non-business capacity and is not on
behalf of PricewaterhouseCoopers.
PricewaterhouseCoopers may monitor outgoing and incoming
e-mails and other telecommunications on its e-mail and
telecommunications systems. By replying to this e-mail you
give your consent to such monitoring
MS Sql Server LazyDBA home page