Solved

MS Access summing on 8-hours

Posted on 2013-01-07
5
285 Views
Last Modified: 2013-01-07
I have a data table with a time stamp (general date format: 1/7/2013 8:49:04 AM) which has a data point for every minute.

I need a sum query to sum on 8-hour periods.
0
Comment
Question by:hgj1357
  • 2
  • 2
5 Comments
 
LVL 2

Author Comment

by:hgj1357
ID: 38751171
This is how I sum on a daily resolution:

SELECT Format([Date-Time],"yyyy-mm-dd") AS MyTIme, Sum(T_41s.Flow) AS SumOfFlow
FROM T_41s
GROUP BY Format([Date-Time],"yyyy-mm-dd");
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 38751233
SELECT Format([Date-Time],"yyyy-mm-dd") AS MyTIme,iif(hour([Date-Time])<8, 1,iif(Hour([Date-Time])<16,2,3)) as MyPeriod, Sum(T_41s.Flow) AS SumOfFlow
FROM T_41s
GROUP BY Format([Date-Time],"yyyy-mm-dd"),iif(hour([Date-Time])<8, 1,iif(Hour([Date-Time])<16,2,3))
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38751255
If you add another table (tbl_Times) to your database, with fields (Title, StartTime, EndTime) and values:

Title      StartTime          EndTime
00-08       #00:00:00#        #08:00:00#
08-16     #08:00:00#        #16:00:00#
16-24   #16:00:00#        #24:00:00#

Then you could do something like:

SELECT Format([Date-Time], "yyyy-mm-dd") & " " & T.Title as Period
             SUM(T_41s.Flow) as SumOfFlow
FROM T_41s
INNER JOIN tbl_Times as T
ON TimeValue(T_41s.[Date-Time]) >= T.StartTime
AND TimeValue(T_41s.[Date-Time]) < T.EndTime
GROUP BY Format([Date-Time], "yyyy-mm-dd") & " " & T.Title
0
 
LVL 2

Author Closing Comment

by:hgj1357
ID: 38751278
Does the job. Thanks
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38751297
If you want to show all of the time ranges for each date, even if no data exists for that range.  Then you could modify my SQL above Like:

SELECT Format([Date-Time], "yyyy-mm-dd") & " " & T.Title as Period
             SUM(iif(TimeValue([Date-Time]) >= T.StartTime AND
                          TimeValue([Date-Time]) < T.EndTime, T_41s.Flow, 0)) as SumOfFlow
FROM T_41s, tbl_Times as T
GROUP BY Format([Date-Time], "yyyy-mm-dd") & " " & T.Title
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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