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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL to calculate half hour summary

Status
Not open for further replies.

aaronlglover

Technical User
Jun 19, 2009
21
US
Hey All,

Does anyone have some SQL to get me started or maybe a link to a help guide that will get me started? I have a table with schedule exception detail that I need to summarize into half hour incrememnts. Here is an example of what the schedule exception detail looks like.

Exception | Start Moment | Stop Moment | Duration |
Break | 3/17/09 02:00 | 3/17/09 03:00 | 60 |
Lunch | 3/17/09 05:00 | 3/17/09 06:15 | 75 |
Break | 3/17/09 07:30 | 3/17/09 08:15 | 45 |

The Query should produce something that looks like this.

Interval | BREAK | LUNCH
02:00 | 30 | 0 |
02:30 | 30 | 0 |
05:00 | 0 | 30 |
05:30 | 0 | 30 |
06:00 | 0 | 15 |
07:30 | 30 | 0 |
08:00 | 15 | 0 |

Thanks!!
 
I would create a table (tblTimeBuckets) of all 48 half hour buckets in a day. It would be easiest of include the start and end times of each.

Then create a crosstab. You will need to figure out the "value" since it is the minutes at either the start or the end of the bucket.

Code:
TRANSFORM First(tblSchedExcept.[Start Moment]) AS [FirstOfStart Moment]
SELECT tblTimeBuckets.FromTIme
FROM tblTimeBuckets, tblSchedExcept
WHERE (((TimeValue([Start Moment]))<[ToTime]) AND ((TimeValue([Stop Moment]))>[FromTime]))
GROUP BY tblTimeBuckets.FromTIme, tblTimeBuckets.ToTime, tblSchedExcept.[Stop Moment], TimeValue([Start Moment]), TimeValue([Stop Moment])
PIVOT tblSchedExcept.Exception;


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top