Help with a date SQL query

C

Ciar?n

I have a table with among other cols a date column in the format
YYYYMMDD and a QTY col, with one row for each day.
The table contains several years data.

What is the best way to sum the QTYs for the First 3 months of 2004
and provide a figure for each month?

I.E. I want to return three rows 200401, 200402 and 200403 with the
sum of QTYs in each row.

Regards,
Ciarán
 
N

Newbie

Try something like

SELECT
Format$(DateSerial(Left$([TrnDate],4),Mid$([TrnDate],5,2),Right$([TrnDate],2
)),"mm/yyyy") AS TDate, Sum(Table1.Qty) AS SumOfQty
FROM Table1
GROUP BY
Format$(DateSerial(Left$([TrnDate],4),Mid$([TrnDate],5,2),Right$([TrnDate],2
)),"mm/yyyy");

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top