Hello all
I have a problem that I can't get around.
I have limited access to our database. I can only use the query tool MS Query to interrogate our data tables, as the results are usually returned to Excel spreadsheets.
I've asked for other query and reporting tools but in the meantime I'm stuck with this.
I don't know if my problem is borne purely of my limitations, those of MS Query or a combination.
I'm trying to return summary sales demand for given periods by items and returning the results grouped by item and period.
I thought a piece of code along the lines of the below would help but MS Query doesn't seem to like a searched CASE statement (I've used the simple CASE statements before without problem).
Any assistance would be very much appreciated.
Mark, HH Associates
I have a problem that I can't get around.
I have limited access to our database. I can only use the query tool MS Query to interrogate our data tables, as the results are usually returned to Excel spreadsheets.
I've asked for other query and reporting tools but in the meantime I'm stuck with this.
I don't know if my problem is borne purely of my limitations, those of MS Query or a combination.
I'm trying to return summary sales demand for given periods by items and returning the results grouped by item and period.
I thought a piece of code along the lines of the below would help but MS Query doesn't seem to like a searched CASE statement (I've used the simple CASE statements before without problem).
Any assistance would be very much appreciated.
Error message said:[red] Didn't expect 'SorMaster' after the SELECT column list[/red]
Code:
SELECT
SorDetail.MStockCode,
Sum(SorDetail.MOrderQty) AS 'Sum of MOrderQty',
[highlight] Mnth =
CASE
WHEN SorMaster.OrderDate BETWEEN {ts '2007-03-01 00:00:00'} And {ts '2007-03-31 00:00:00'}
THEN 'Mar'
WHEN SorMaster.OrderDate BETWEEN {ts '2007-04-01 00:00:00'} And {ts '2007-04-30 00:00:00'}
THEN 'Apr'
WHEN SorMaster.OrderDate BETWEEN {ts '2007-05-01 00:00:00'} And {ts '2007-05-31 00:00:00'}
THEN 'May'
WHEN SorMaster.OrderDate BETWEEN {ts '2007-06-01 00:00:00'} And {ts '2007-06-30 00:00:00'}
THEN 'Jun'
ELSE 'XXX'
END[/highlight]
FROM
SysproCompanyH.dbo.SorDetail SorDetail
INNER JOIN SysproCompanyH.dbo.SorMaster SorMaster
ON SorDetail.SalesOrder = SorMaster.SalesOrder
WHERE
(SorDetail.MWarehouse='BM')
AND (SorMaster.OrderStatus Not In ('*','\')
AND (SorMaster.OrderDate Between {ts '2007-03-01 00:00:00'} And {ts '2007-06-10 00:00:00'}))
GROUP BY
SorDetail.MStockCode, Mnth
ORDER BY
SorDetail.MStockCode
Mark, HH Associates