barnettjacob
IS-IT--Management
Hi, hoping someone can help me with a query I need to write to summarise the components of a retail transaction where the transaction details are in one table (saleheader) but the details are in the other (saleline).
My aim is a query that, for each transaction (reference1) on the saleheader table, returns the sum of sales for each Division (analysis1code) which is stored in the saleline table.
Reference1 is the link between the two tables.
My attempt (which doesn't come close to working) was:
If anybody could help me out I would be eternally grateful!
Regards
Jacob
My aim is a query that, for each transaction (reference1) on the saleheader table, returns the sum of sales for each Division (analysis1code) which is stored in the saleline table.
Reference1 is the link between the two tables.
My attempt (which doesn't come close to working) was:
Code:
select
reference1,
branchcode,
(select sum(case when analysis1code = 'baby' then (fcextendednetamount-fcextendedtaxamount) else 0 end) from eee..vwsaleline_gp) as 'H&T',
(select sum(case when analysis1code = 'fashion' then (fcextendednetamount-fcextendedtaxamount) else 0 end) from eee..vwsaleline_gp) as 'Apparel',
(select sum(case when analysis1code = 'giftware' then (fcextendednetamount-fcextendedtaxamount) else 0 end) from eee..vwsaleline_gp) as 'T&G'
from eee..vwsaleheader_gp
where saledate >= '12/01/11'
If anybody could help me out I would be eternally grateful!
Regards
Jacob