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 2008 Forums
 Transact-SQL (2008)
 Count by Hours

Author  Topic 

alistair4267
Starting Member

10 Posts

Posted - 2011-11-16 : 10:03:22
Hi All

I have two databases with the following columns

--Person Table--
PersoniID (PK)
CreateDateTime
EmailAddress

--Order Table--
PersonID (FK)
CreateDateTime
OrderID
OrderDateTime
Status

The problem i am having is that i need to report on how many order have come in for a specific hour for a specific company (see below, this is what i would like)

CompanyName | 8AM | 9am | 10am | 11am
ABC 123 10 5 6 5
Big C 15 0 0 25

Could some possible point me in the right direction on how i could achieve this ?

Kind Regards
Alistair



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-16 : 10:30:01
GROUP BY DATEPART(hh,datevalue) and apply pivot over it

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

Go to Top of Page
   

- Advertisement -