SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 15 Minuter Intervals
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sergeant_time
Yak Posting Veteran

68 Posts

Posted - 04/16/2012 :  16:43:00  Show Profile  Reply with Quote
I am trying to write code to group times by 15 minute intervals. I was able to get the followig code to work, but I am stuck trying to group it. Below is a sample code I have.

select
[5min] = dateadd(minute,(datediff(minute,0,a.dt)/5)*5,0),
[10min] = dateadd(minute,(datediff(minute,0,a.dt)/10)*10,0),
[15min] = dateadd(minute,(datediff(minute,0,a.dt)/15)*15,0),
[20min] = dateadd(minute,(datediff(minute,0,a.dt)/20)*20,0),
[30min] = dateadd(minute,(datediff(minute,0,a.dt)/30)*30,0),
a.dt
from
(select dt = convert(datetime,'2005-11-07 19:55:19.757') ) a

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 04/16/2012 :  16:47:18  Show Profile  Reply with Quote
so what should be your output? you want above division to be applied for each datevalue in table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29138 Posts

Posted - 04/16/2012 :  16:48:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, '19000101', dt) / 15 * 15, '19000101'), COUNT(*)
FROM dbo.Table
GROUP BY DATEADD(MINUTE, DATEDIFF(MINUTE, '19000101', dt) / 15 * 15, '19000101')
ORDER BY DATEADD(MINUTE, DATEDIFF(MINUTE, '19000101', dt) / 15 * 15, '19000101')



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 04/16/2012 :  16:50:48  Show Profile  Reply with Quote
http://visakhm.blogspot.com/2010/02/aggregating-data-over-time-slots.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sergeant_time
Yak Posting Veteran

68 Posts

Posted - 04/17/2012 :  08:39:43  Show Profile  Reply with Quote
I am trying to group the number of calls that arrived in queue into 15 minute intervals.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29138 Posts

Posted - 04/17/2012 :  09:50:09  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Yes, we understand. See my solution posted 04/16/2012 : 16:48:05


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

sergeant_time
Yak Posting Veteran

68 Posts

Posted - 04/17/2012 :  11:06:39  Show Profile  Reply with Quote
@ SwePeso
I was able to get your solution and the code below to work.

DATEADD(MINUTE, DATEDIFF(MINUTE, 0, queued_time) / 15 * 15, 0)

My follow on question is how can both codes to round up to nearest 15 minute.


Thank you!
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

3826 Posts

Posted - 04/17/2012 :  11:42:04  Show Profile  Reply with Quote
What do you mean by "Round?" Do you mean the ceiling? As in, if the time is 12:16 it should go to 12:30?
Go to Top of Page

sergeant_time
Yak Posting Veteran

68 Posts

Posted - 04/17/2012 :  11:58:45  Show Profile  Reply with Quote
Disreguard! Silly me. The code works find and it matches the data I am comparing it to. Thanks everyone
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000