August 1, 2005 at 9:18 am
Hi
I have a view with the turnovers. Fields are Year, Month, Client, Turnover.
I have a second view with the costs. Fields are Year, Month, Client, Costs.
Now I have created a view combining these two.
select turnover.customer, turnover.year, turnover.month, turnover.turnover, costs.costs
from turnover full outer join costs
on turnover.client = costs.client and turnover.year = costs.year and turnover.month = costs.month
The results I should get, I guess, are all records from turnover and all records from costs. Well, I receive all records from turnover (so even if costs is null) but not all records from costs (those where turnover is null). How come ?
Haven't got a clue.
Thx J
JV
August 1, 2005 at 10:08 am
You should really look at the data because you are supposed to get the matches and the missmatches too
BTW : your select has a "customer" column not identified in any of the definitions
* Noel
August 2, 2005 at 12:10 am
Try:
SELECT COALESCE(turnover.client,costs.client) AS Client
, COALESCE(turnover.[year],costs.[year]) AS [Year]
, COALESCE(turnover.[month], costs.[month]) AS [Month]
, turnover.turnover, costs.costs
FROM turnover
FULL OUTER JOIN costs ON turnover.client = costs.client
AND turnover.[year] = costs.[year]
AND turnover.[month] = costs.[month]
Andy
August 2, 2005 at 1:45 am
Noeld
Sorry customer is same as client. This is not my real qquery but simple translation. Andy thx, I will giev it shot. Learned again !
Thx
J
JV
August 2, 2005 at 4:03 am
David
Much obliged, it works super !!
I still need to learn a lot.
Thx J
JV
August 2, 2005 at 8:06 am
If that (David's) query worked yours returned all the records!! Contrary to what you said!
The only difference was in the column population not on missing records
* Noel
August 2, 2005 at 8:12 am
Nope, sorry.
Strangely enough it didn't show all records. Now it does.
JV
August 2, 2005 at 8:35 am
Well, you tell me if I am blind but:
Your query record source:
from
turnover full outer join costs
on turnover.client = costs.client
and turnover.year = costs.year
and turnover.month = costs.month
and David's record source
FROM turnover FULL OUTER JOIN costs
ON turnover.client = costs.client
AND turnover.[year] = costs.[year]
AND turnover.[month] = costs.[month]
look IDENTICAL to me and that is what determines the # of records you get back!!!
* Noel
August 10, 2005 at 12:34 am
Noel,
Since this is a FULL OUTER JOIN the problem was in:
SELECT turnover.client
, turnover.[year]
, turnover.[month]
, turnover.turnover, costs.costs
Caused the costs fields not being included in the output, so using COALESCE caused both to be included when it was their time to be NULL.
SELECT COALESCE(turnover.client,costs.client) AS Client
, COALESCE(turnover.[year],costs.[year]) AS [Year]
, COALESCE(turnover.[month], costs.[month]) AS [Month]
, turnover.turnover, costs.costs
Andy
August 10, 2005 at 1:03 am
Thx Andy
Indeed the result was different, and I have now the one I need.
JV
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply