Question : How do I add the YTD Column to this query in Access?

Here is the Today, MTD query I have now.  I can add the 3rd GLTest(G3) table to create the YTD field....   SUM(G3.amount) AS YTD.  My question is... what does the WHERE clause look like?


SELECT G1.trandate, G1.desc, G1.amount AS Today, Sum(G2.amount) AS MTD
FROM GLTest AS G1 LEFT JOIN GLTest AS G2 ON G1.desc = G2.desc
WHERE (((G2.trandate)>=DateSerial(Year([G1].[trandate]),Month([G1].[trandate]),1) And (G2.trandate)<=[G1].[trandate]))
GROUP BY G1.trandate, G1.desc, G1.amount
HAVING (((G1.trandate)=#2/15/2009#));

Answer : How do I add the YTD Column to this query in Access?

Here's another way:

See how it builds?

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
SELECT EnterDate, Desc, 
DSum("Amount","GLTest","[Date] = EnterDate") AS SumThisDate,
DSum("Amount","GLTest","[Date] BETWEEN DateSerial(Year(EnterDate),Month(EnterDate),1) AND EnterDate") AS MTD
DSum("Amount","GLTest","[Date] BETWEEN DateSerial(Year(EnterDate),1,1) AND EnterDate") AS YTD

FROM GLTest;

SELECT a.EnterDate, a.Desc,
(SELECT Sum(b.Amount) FROM GLTest b WHERE b.Desc = a.Desc AND b.[Date] = a.EnterDate) AS SumThisDate,
(SELECT Sum(b.Amount) FROM GLTest c WHERE c.Desc = a.Desc AND c.[Date] BETWEEN DateSerial(Year(EnterDate),Month(EnterDate),1) AND EnterDate) AS MTD,
etc.
FROM GLTest a;
Random Solutions  
 
programming4us programming4us