hanchilicious
Programmer
Hi,
I'm fairly new to SQL Server, and I'm using SQL Server 8.
I was wondering if someone would be able to take a look at this with me.
I have two tables TSRDB and TSR_LY. TSRDB is the driving table, containing customer and sales data for one fiscal quarter. TSR_LY does the same thing, but contains all four quarters from last year only.
If I run a straight query against TSRDB where class = 'IP' and country = 'FRANCE', I get a total of 18519. The same query on TSR_LY for the corresponding quarter reveals 8055. This is fine.
What I want to achieve is a single query illustrating 18519 for this Q1 this year, and 8055 for Q1 last year, even though some customers and products may not be in both tables.
I have the following:
Although I get 18519 for Q107, I get 5915 for Q106, a shortage of some 2000. The join uses all dimension fields, so I can't tighten that up anymore, and I would have thought that using a full outer join would ensure that records in TSR_LY that are not in TSRDB would not diminish the Q106 total.
(The either/or criteria produce the same results, I'm just not sure if I drive the criteria from TSRDB alone, whether I will miss customers and products in TSR_LY who do not appear in TSRDB.)
Does anyone have any idea of what I should be looking out for here? I'm running a bit low on ideas.
Thanks
I'm fairly new to SQL Server, and I'm using SQL Server 8.
I was wondering if someone would be able to take a look at this with me.
I have two tables TSRDB and TSR_LY. TSRDB is the driving table, containing customer and sales data for one fiscal quarter. TSR_LY does the same thing, but contains all four quarters from last year only.
If I run a straight query against TSRDB where class = 'IP' and country = 'FRANCE', I get a total of 18519. The same query on TSR_LY for the corresponding quarter reveals 8055. This is fine.
What I want to achieve is a single query illustrating 18519 for this Q1 this year, and 8055 for Q1 last year, even though some customers and products may not be in both tables.
I have the following:
Code:
select
sum(tsrdb.week1a) Q107,
sum(tsr_ly.week1a) Q106
from tsrdb
full OUTER JOIN TSR_LY
ON TSRDB.TruePPN = TSR_LY.TruePPN
AND TSRDB.TrueSalesDistrictID = TSR_LY.TrueSalesDistrictID
AND TSRDB.TrueSalesOrg = TSR_LY.TrueSalesOrg
AND TSRDB.TrueID = TSR_LY.TrueID
AND TSRDB.ClassID = TSR_LY.ClassID
AND TSRDB.HQID = TSR_LY.HQID
AND TSRDB.PPN = TSR_LY.PPN
AND TSRDB.SAPID = TSR_LY.SAPID
AND TSRDB.LY_FQ = TSR_LY.FQuarter
WHERE TSRDB.TrueSalesOrg = 'FRANCE'
-- either
AND tsrdb.fquarter = '2007.1'
AND tsrdb.classid = 'IP'
-- or
and (tsrdb.fquarter = '2007.1' or tsr_ly.fquarter = '2006.1')
and (tsrdb.classid = 'IP' or tsr_ly.classid = 'IP')
--
(The either/or criteria produce the same results, I'm just not sure if I drive the criteria from TSRDB alone, whether I will miss customers and products in TSR_LY who do not appear in TSRDB.)
Does anyone have any idea of what I should be looking out for here? I'm running a bit low on ideas.
Thanks