R
ram
HI I would like assistance with creating a year to date subquery. I tried to
copy the MS help example but still can't get the query to run. I have the
following:
Table name Orders
Field Names- [ID] ( system generated primary key) , [OrdersDate],
[Quantity], [UnitPrice]
Query SQL -
SELECT Year([Orders].[OrderDate]) AS TheYear,
Month([Orders].[OrderDate]) AS TheMonth,
Sum([Orders].[Quantity]*[Orders].[UnitPrice]) AS MonthAmount,
(SELECT Sum(dupe.Quantity * dupe.UnitPrice) AS YTD
FROM Orders AS A INNER JOIN [Orders] AS dupe ON orders.ID = dupe.ID
WHERE orders.OrderDate >= DateSerial(Year([Orders].[OrderDate]),1,1)
AND orders.OrderDate < DateSerial(Year([Orders].[OrderDate]),
Month([Orders].[OrderDate]) + 1, 1))
AS YTDAmount
GROUP BY Year([Orders].[OrderDate]), Month([Orders].[OrderDate]);
Thanks in advance for any help
copy the MS help example but still can't get the query to run. I have the
following:
Table name Orders
Field Names- [ID] ( system generated primary key) , [OrdersDate],
[Quantity], [UnitPrice]
Query SQL -
SELECT Year([Orders].[OrderDate]) AS TheYear,
Month([Orders].[OrderDate]) AS TheMonth,
Sum([Orders].[Quantity]*[Orders].[UnitPrice]) AS MonthAmount,
(SELECT Sum(dupe.Quantity * dupe.UnitPrice) AS YTD
FROM Orders AS A INNER JOIN [Orders] AS dupe ON orders.ID = dupe.ID
WHERE orders.OrderDate >= DateSerial(Year([Orders].[OrderDate]),1,1)
AND orders.OrderDate < DateSerial(Year([Orders].[OrderDate]),
Month([Orders].[OrderDate]) + 1, 1))
AS YTDAmount
GROUP BY Year([Orders].[OrderDate]), Month([Orders].[OrderDate]);
Thanks in advance for any help