N
Noreen McHugh
Hi
I have used an example from the Northwind sample database to write a query
to show running totals for the current year, but I am hust getting an error
in my running total column. Can somebody hae a look at my SQL and possibly
give me some ideas about where I am going wrong
SELECT QueryTY.Date, QueryTY.StoreId, QueryTY.[AM Read Tot], QueryTY.[PM
Read Tot], QueryTY.[AM Cust C], QueryTY.[PM Cust C], QueryTY.[LY Date],
QueryLY.[AM Read Tot], QueryLY.[PM Read Tot], QueryLY.[AM Cust C],
QueryLY.[PM Cust C], QueryLY.[Staff Food], QueryTY.County, QueryTY.Company,
QueryTY.[Fresh Express], QueryTY.Relish, [QueryTY.AM Read Tot]+[QueryTY.PM
Read Tot] AS [TY Read Total], [QueryLY.AM Read Tot]+[QueryLY.PM Read Tot] AS
[LY Read Total], [QueryTY.AM Cust C]+[QueryTY.PM Cust C] AS [TY CCount],
[QueryLY.AM Cust C]+[QueryLY.PM Cust C] AS [LY CCount], [TY Read Total]/[TY
CCount] AS [TY Ave S], [LY Read Total]/[LY CCount] AS [LY Ave S],
DatePart("yyyy",[QueryTY.Date]) AS AYear, DatePart("m",[QueryTY.Date]) AS
AMonth, DSum("TY Read Total","DatePart (''m', [QueryTY.Date] )<= " &
[AMonth] & " And DatePart( 'yyyy', [QueryTY.Date] ) =" & [AYear] & "") AS
RunTot
FROM QueryTY INNER JOIN QueryLY ON (QueryTY.StoreId = QueryLY.StoreId) AND
(QueryTY.[LY Date] = QueryLY.Date)
WHERE (((DatePart("yyyy",[QueryTY.Date]))>=2005))
GROUP BY QueryTY.Date, QueryTY.StoreId, QueryTY.[AM Read Tot], QueryTY.[PM
Read Tot], QueryTY.[AM Cust C], QueryTY.[PM Cust C], QueryTY.[LY Date],
QueryLY.[AM Read Tot], QueryLY.[PM Read Tot], QueryLY.[AM Cust C],
QueryLY.[PM Cust C], QueryLY.[Staff Food], QueryTY.County, QueryTY.Company,
QueryTY.[Fresh Express], QueryTY.Relish, [QueryTY.AM Read Tot]+[QueryTY.PM
Read Tot], [QueryLY.AM Read Tot]+[QueryLY.PM Read Tot], [QueryTY.AM Cust
C]+[QueryTY.PM Cust C], [QueryLY.AM Cust C]+[QueryLY.PM Cust C], [TY Read
Total]/[TY CCount], [LY Read Total]/[LY CCount],
([QueryTY].[Date])>#1/1/2005#, DatePart("yyyy",[QueryTY.Date]),
DatePart("m",[QueryTY.Date])
HAVING (((QueryTY.Date)>#6/1/2005#) AND
((([QueryTY].[Date])>#1/1/2005#)<#12/31/2005#))
ORDER BY DatePart("yyyy",[QueryTY.Date]), DatePart("m",[QueryTY.Date]);
Regards
Noreen
I have used an example from the Northwind sample database to write a query
to show running totals for the current year, but I am hust getting an error
in my running total column. Can somebody hae a look at my SQL and possibly
give me some ideas about where I am going wrong
SELECT QueryTY.Date, QueryTY.StoreId, QueryTY.[AM Read Tot], QueryTY.[PM
Read Tot], QueryTY.[AM Cust C], QueryTY.[PM Cust C], QueryTY.[LY Date],
QueryLY.[AM Read Tot], QueryLY.[PM Read Tot], QueryLY.[AM Cust C],
QueryLY.[PM Cust C], QueryLY.[Staff Food], QueryTY.County, QueryTY.Company,
QueryTY.[Fresh Express], QueryTY.Relish, [QueryTY.AM Read Tot]+[QueryTY.PM
Read Tot] AS [TY Read Total], [QueryLY.AM Read Tot]+[QueryLY.PM Read Tot] AS
[LY Read Total], [QueryTY.AM Cust C]+[QueryTY.PM Cust C] AS [TY CCount],
[QueryLY.AM Cust C]+[QueryLY.PM Cust C] AS [LY CCount], [TY Read Total]/[TY
CCount] AS [TY Ave S], [LY Read Total]/[LY CCount] AS [LY Ave S],
DatePart("yyyy",[QueryTY.Date]) AS AYear, DatePart("m",[QueryTY.Date]) AS
AMonth, DSum("TY Read Total","DatePart (''m', [QueryTY.Date] )<= " &
[AMonth] & " And DatePart( 'yyyy', [QueryTY.Date] ) =" & [AYear] & "") AS
RunTot
FROM QueryTY INNER JOIN QueryLY ON (QueryTY.StoreId = QueryLY.StoreId) AND
(QueryTY.[LY Date] = QueryLY.Date)
WHERE (((DatePart("yyyy",[QueryTY.Date]))>=2005))
GROUP BY QueryTY.Date, QueryTY.StoreId, QueryTY.[AM Read Tot], QueryTY.[PM
Read Tot], QueryTY.[AM Cust C], QueryTY.[PM Cust C], QueryTY.[LY Date],
QueryLY.[AM Read Tot], QueryLY.[PM Read Tot], QueryLY.[AM Cust C],
QueryLY.[PM Cust C], QueryLY.[Staff Food], QueryTY.County, QueryTY.Company,
QueryTY.[Fresh Express], QueryTY.Relish, [QueryTY.AM Read Tot]+[QueryTY.PM
Read Tot], [QueryLY.AM Read Tot]+[QueryLY.PM Read Tot], [QueryTY.AM Cust
C]+[QueryTY.PM Cust C], [QueryLY.AM Cust C]+[QueryLY.PM Cust C], [TY Read
Total]/[TY CCount], [LY Read Total]/[LY CCount],
([QueryTY].[Date])>#1/1/2005#, DatePart("yyyy",[QueryTY.Date]),
DatePart("m",[QueryTY.Date])
HAVING (((QueryTY.Date)>#6/1/2005#) AND
((([QueryTY].[Date])>#1/1/2005#)<#12/31/2005#))
ORDER BY DatePart("yyyy",[QueryTY.Date]), DatePart("m",[QueryTY.Date]);
Regards
Noreen