Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL-PROBLEM

Status
Not open for further replies.

lode

Programmer
Nov 8, 2001
208
BE
Hi,

I've a Access-databasetable, and one of the fields is a date.
How can I retrieve the sum of those records for every month with an sql-instruction.

Thanks
Lode.

 
&quot;SELECT SUM(Questions)as Question, FROM qryStats WHERE OrigDate >= # &quot; & DTPBegin.Value & &quot; # AND OrigDate <= # &quot; & DTPEnd.Value & &quot; # &quot;

You can either SUM() a field or COUNT() a field over a specific date range.
 
I would use the following example SQL statement:
[tt]
SELECT Format(YourDateField,'m/yyyy'), SUM(AFieldToSummarize)
FROM YourTable
GROUP BY Format(YourDateField,'m/yyyy')
[/tt]
or if you prefer using fields that aren't overloaded...
[tt]
SELECT Month(YourDateField), Year(YourDateField), SUM(AFieldToSummarize)
FROM YourTable
GROUP BY Month(YourDateField), Year(YourDateField)
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top