Trying to write a query to find "lost customers". Fist I want to pull 2005 YTD Sales, then sales by period in columns to the right, looks something like this:
Cust# CustName YTD05Sales Jan06Sales Feb06Sales etc
My problem is that to get the sales numbers, I have to use a where clause since the sales are not held in their own columns in the table.
Getting the 2005YTD is easy, but how do I add columns to the right????
Here is my starting point (with addl columns not described above):
Select
FFDARCD"A/S/D",FFCCUSN"Cust#",FFCCNMB"CustNm",FFDDTEI"LastOrdDt",
sum(HHHEXSN)"SlsNet",FFDCDTE"CreateDt",FFDDTBC"FirstOrd", FFDDTEI”LastOrdr”
From ((FFCCSTAL0 Left Outer Join HHHORDHL0 on FFCCUSN=HHHCUSN)
Left Outer Join FFDCSTBL0 on FFCCUSN=FFDCUSN)
Where (HHHFSYR=2005)
Group By
FFDARCD,FFCCUSN,FFCCNMB,FFDDTEI,FFDCDTE,FFDDTBC, FFDDTEI
Order By FFDDTEI Desc
Basically trying to create a quasi-spread sheet that I want to add some CASE logic to later to compare the FY2005Sales to the 2006 months on an ongoing basis.
Hope someone has an idea.
Thanks,
Robert
Cust# CustName YTD05Sales Jan06Sales Feb06Sales etc
My problem is that to get the sales numbers, I have to use a where clause since the sales are not held in their own columns in the table.
Getting the 2005YTD is easy, but how do I add columns to the right????
Here is my starting point (with addl columns not described above):
Select
FFDARCD"A/S/D",FFCCUSN"Cust#",FFCCNMB"CustNm",FFDDTEI"LastOrdDt",
sum(HHHEXSN)"SlsNet",FFDCDTE"CreateDt",FFDDTBC"FirstOrd", FFDDTEI”LastOrdr”
From ((FFCCSTAL0 Left Outer Join HHHORDHL0 on FFCCUSN=HHHCUSN)
Left Outer Join FFDCSTBL0 on FFCCUSN=FFDCUSN)
Where (HHHFSYR=2005)
Group By
FFDARCD,FFCCUSN,FFCCNMB,FFDDTEI,FFDCDTE,FFDDTBC, FFDDTEI
Order By FFDDTEI Desc
Basically trying to create a quasi-spread sheet that I want to add some CASE logic to later to compare the FY2005Sales to the 2006 months on an ongoing basis.
Hope someone has an idea.
Thanks,
Robert