Wednesday, March 28, 2012

Query - Join:

What type of Query should I use to combine two sets of data into the same
recordset. Note that none of the companies in TableA are the same as the
companies in TableB (distinct sets of data).
TableA
Company, Sales, Members
Table B
Company, Members, Vacation
Query Should Produce
Company, Sales, Members Vacations"William" <da@.northernit.net> wrote in message
news:ikoke.16188$tM3.4933@.twister.nyroc.rr.com...
> What type of Query should I use to combine two sets of data into the same
> recordset. Note that none of the companies in TableA are the same as the
> companies in TableB (distinct sets of data).
> TableA
> Company, Sales, Members
> Table B
> Company, Members, Vacation
> Query Should Produce
> Company, Sales, Members Vacations
>
If you know that they are definitely distinct, then you could simply do the
following:
INSERT dbo.TableA (Company, Sales, Members, Vacations)
SELECT Company, NULL, Members, Vacation
FROM dbo.TableB
Rick Sawtell
MCT, MCSD, MCDBA|||Are there any matching values between the two tables (e.g. Members)? If so,
the
following might work:
Select Coalesce(TableA.Company, TableB.Company) As Company
, TableA.Sales
, Coalesce(TableA.Members, TableB.Members) As Members
, TableB.Vacation
From TableA
Full Join TableB
On TableA.Members = TableB.Members
If there is nothing in common, then you could get the results you want using
a
Union like so:
Select A.Company, A.Sales, A.Members, Null As Vacation
From TableA As A
Union
Select B.Company, Null, B.Members, B.Vacation
From TableB As B
Using Union will give you a distinct list across the two tables. Using Union
All
will give you all items from both tables even if a duplicate is produced.
Thomas
"William" <da@.northernit.net> wrote in message
news:ikoke.16188$tM3.4933@.twister.nyroc.rr.com...
> What type of Query should I use to combine two sets of data into the same
> recordset. Note that none of the companies in TableA are the same as the
> companies in TableB (distinct sets of data).
> TableA
> Company, Sales, Members
> Table B
> Company, Members, Vacation
> Query Should Produce
> Company, Sales, Members Vacations
>

No comments:

Post a Comment