K
Kevin Labore
Hi
the following SQL is obvisouly not working I simply wrote for viewing
What I want is for to generate a crosstab based on StartDate and EndDate (at
runtime)
so for example if a person enter 5/10/04(StartDate) and 6/10/05(EndDate) it
will only include those dates between 5/10 and 6/10 (for this year and last
year) but anything else (ie.no other dates in June (after 10th) or the other
dates between 6/10/04 and 5/10/05. I know I am missing the logic on this one
Below is SQL ---- Can some tell me how to go about this?
Thanks
Kevin
----------------------------------------------------
PARAMETERS StartDate DateTime, EndDate DateTime;
TRANSFORM Sum([DeptsSales Query].DeptSales) AS SumOfDeptSales
SELECT [DeptsSales Query].DeptDesc, Depts.OrderPerson, Avg([DeptsSales
Query].DeptSales) AS [AVG Of DeptSales], Sum([DeptsSales Query].DeptSales)
AS TotalDeptSales
FROM [DeptsSales Query] INNER JOIN Depts ON ([DeptsSales Query].DeptDesc =
Depts.DeptDesc) AND ([DeptsSales Query].DeptNum = Depts.DeptNum)
WHERE (((Month([DeptDate])) Between Month([StartDate]) And Month([EndDate]))
AND ((Day([deptdate])) Between Day([StartDate]) And Day([EndDate])))
GROUP BY [DeptsSales Query].DeptDesc, Depts.OrderPerson
ORDER BY [DeptsSales Query].DeptDesc, Depts.OrderPerson,
DatePart("yyyy",[deptdate],1,1) DESC
PIVOT DatePart("yyyy",[deptdate],1,1);
---------------------------------------------------------
the following SQL is obvisouly not working I simply wrote for viewing
What I want is for to generate a crosstab based on StartDate and EndDate (at
runtime)
so for example if a person enter 5/10/04(StartDate) and 6/10/05(EndDate) it
will only include those dates between 5/10 and 6/10 (for this year and last
year) but anything else (ie.no other dates in June (after 10th) or the other
dates between 6/10/04 and 5/10/05. I know I am missing the logic on this one
Below is SQL ---- Can some tell me how to go about this?
Thanks
Kevin
----------------------------------------------------
PARAMETERS StartDate DateTime, EndDate DateTime;
TRANSFORM Sum([DeptsSales Query].DeptSales) AS SumOfDeptSales
SELECT [DeptsSales Query].DeptDesc, Depts.OrderPerson, Avg([DeptsSales
Query].DeptSales) AS [AVG Of DeptSales], Sum([DeptsSales Query].DeptSales)
AS TotalDeptSales
FROM [DeptsSales Query] INNER JOIN Depts ON ([DeptsSales Query].DeptDesc =
Depts.DeptDesc) AND ([DeptsSales Query].DeptNum = Depts.DeptNum)
WHERE (((Month([DeptDate])) Between Month([StartDate]) And Month([EndDate]))
AND ((Day([deptdate])) Between Day([StartDate]) And Day([EndDate])))
GROUP BY [DeptsSales Query].DeptDesc, Depts.OrderPerson
ORDER BY [DeptsSales Query].DeptDesc, Depts.OrderPerson,
DatePart("yyyy",[deptdate],1,1) DESC
PIVOT DatePart("yyyy",[deptdate],1,1);
---------------------------------------------------------