Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mattd_nz
Starting Member
6 Posts |
Posted - 2006-03-22 : 22:03:14
|
| Hi I have a table full of records loaded with a time stamp in a standared datetime field called start_time; 2006-01-22 00:00:12.000Over a period of 24 hrs I want to pull out something that will look roughly like:Time Record Count18:00 45718:05 56218:10 377etc.So far the best I've come up with is this..... Any help moving forward would be gratefully accepted.select count(*) CdrsIn5Min from cdrtablewhere start_time between dateadd(mi,-5,'2006-03-22 10:00:00') and '2006-03-22 10:00:00' CdrsIn5Min ----------- 528(1 row(s) affected) |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-22 : 22:21:37
|
[code]declare @table table ( time_stamp datetime )insert into @tableselect '2006-03-23 18:00:00' union allselect '2006-03-23 18:01:00' union allselect '2006-03-23 18:02:00' union allselect '2006-03-23 18:02:10' union allselect '2006-03-23 18:03:00' union allselect '2006-03-23 18:04:00' union allselect '2006-03-23 18:05:00' union allselect '2006-03-23 18:06:00' union allselect '2006-03-23 18:06:10' union allselect '2006-03-23 18:06:20' union allselect '2006-03-23 18:07:00' union allselect '2006-03-23 18:08:00' union allselect '2006-03-23 18:10:02' union allselect '2006-03-23 18:10:04' union allselect '2006-03-23 19:00:05'select dateadd(minute, datediff(minute, 0, time_stamp) / 5 * 5, 0) as [Time], count(*) as [Record Count]from @tablegroup by dateadd(minute, datediff(minute, 0, time_stamp) / 5 * 5, 0)[/code] KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
mattd_nz
Starting Member
6 Posts |
Posted - 2006-03-22 : 22:52:17
|
| Ace, thanks a lot. Reports are now winging their happy way to management :) |
 |
|
|
|
|
|
|
|