The following query:
select coalesce(to_number(bl.division_code), bud.division) division
, coalesce(bud.glaccountcode, bl.costcenter_costanalysis_period_periods_year_years_balance_code_attr) glaccountcode
, coalesce(bud.costcenter, bl.costcenter_code_attr) costcenter
, coalesce(bud.costunit, bl.code_attr) costunit
, coalesce(bud.reportingyear, bl.costcenter_costanalysis_period_periods_year_reportingyear_attr) reportingyear
, coalesce(bud.reportingperiod, bl.costcenter_costanalysis_period_reportingperiod_attr) reportingperiod
, case when bud.amountdc > 0 then 456 else null end budgetamountdc label 'Budget (anonymized, EUR)'
, case when bl.balance > 0 then 123 else null end actualsamountdc label 'Actuals (anonymized, EUR)'
, case
when bl.division_code is null
then 'budget'
when bud.division is null
then 'balancelines'
else 'both'
end
label 'Source'
from exactonlinexml..balancelinesperperiodcostanalysis bl
full
outer
join exactonlinerest..budgets bud
on bud.division = to_number(bl.division_code)
and bud.glaccountcode = bl.costcenter_costanalysis_period_periods_year_years_balance_code_attr
and bud.costcenter = bl.costcenter_code_attr
and bud.costunit = bl.code_attr
and bud.reportingyear = bl.costcenter_costanalysis_period_periods_year_reportingyear_attr
and bud.reportingperiod = bl.costcenter_costanalysis_period_reportingperiod_attr
joins actual transactions on General Ledger accounts with associated budgets on a detailed level:
- Exact Online company (
division_code
) - Financial year (
reportingyear
) - Financial period (
reportingperiod
) - General Ledger account (
glaccountcode
) - Cost center (
costcenter
) - Costunit (
costunit
)
I expect at most one row of data per combination of those dimensions. However, for some combination, 2 rows are returned. One of these rows has a label 'budget' whereas the other one has 'balancelines'.
It seems that somehow they are not merged together in the coalesce:
The contents of gl account 5050 in balance lines of period 1 in 2019 is one row with a certain amount (not equal 0).
The contents of GL account 5050 in budgets of period 1 in 2019 is also one row with a certain amount (not equal 0).
I seem unable to find why the rows are not merged together by the full outer join and coalesce.
What am I doing wrong?