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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Grouping Query By Hour

Author  Topic 

paultervit
Starting Member

10 Posts

Posted - 2008-07-23 : 05:11:38
Hello All
Can someone tell me if there is a function similar to Date for Hour. i.e. I have a table with time entries and I would like to group these by day then hour. For Day I can user Day(date_time). Is there anything similar I can use for hour?

Thanks

Paul

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-23 : 05:14:08
select dateadd(hh,datediff(hh,0,yourdatefield),0),agregatedfields
from yourtable
group by dateadd(hh,datediff(hh,0,yourdatefield),0)
Go to Top of Page

paultervit
Starting Member

10 Posts

Posted - 2008-07-23 : 05:19:47
thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-23 : 05:22:28
quote:
Originally posted by visakh16

select dateadd(hh,datediff(hh,0,yourdatefield),0),agregatedfields
from yourtable
group by dateadd(hh,datediff(hh,0,yourdatefield),0)


Just for clarity I use hour in instead of hh

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-23 : 05:33:27
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

select dateadd(hh,datediff(hh,0,yourdatefield),0),agregatedfields
from yourtable
group by dateadd(hh,datediff(hh,0,yourdatefield),0)


Just for clarity I use hour in instead of hh

Madhivanan

Failing to plan is Planning to fail


yup...you can use hour or hh
i prefer using short form
Go to Top of Page
   

- Advertisement -