Solved

Aggregating fields based on datetime month and day

Posted on 2013-06-06
1
238 Views
Last Modified: 2013-06-06
Dear all,

I would like to create a monthly and daily queries to aggregate fields, i.e. buildingcost, numberMonths for buildDateTime.

i.e. Montly Aggregate

buildDateTime            buildingcost
01/01/2004 00:00:00  9
02/01/2004 00:00:00  10

Returning:

buildDateTime  buildingcost
01/2004             19

etc.

I've tried the following without success:

SELECT table1.buildDateTime, SUM(table1.buildingcost), SUM(table1.numberMonths
FROM buildDateTime
WHERE (table1.buildDateTime>= #01/01/2002 00:00:00# AND table1.buildDateTime< #01/12/2002 00:00:00#)
GROUP BY table1.buildDateTime; // how do I specify the month and year

Open in new window


Thanks
0
Comment
Question by:AndyC1000
1 Comment
 
LVL 77

Accepted Solution

by:
peter57r earned 280 total points
ID: 39224874
SELECT format(buildDateTime, "yyyy/mm") as Period, SUM(buildingcost) as TotCost

FROM buildDateTime

GROUP BY format(buildDateTime, "yyyy/mm")
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now