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 2000 Forums
 SQL Server Development (2000)
 breaking down results by hour

Author  Topic 

php95saj
Starting Member

43 Posts

Posted - 2002-12-09 : 11:52:35
Guys
I have a tabe which is storing user response round the clock. I am using GetDate() to store DateTimeStamp I want to build a report that would generate a report on hourly basis. i.e. During
8-9 09
9-10 134
10-11 2057
11-12 2937
something like that.
Thanks


Sharjeel

colinm
Yak Posting Veteran

62 Posts

Posted - 2002-12-09 : 12:02:07
Use the datepart function.
i.e.

SELECT DATEPART(hh,DateTimeStamp) AS HOUR, COUNT(*) AS TOTAL FROM tbl
GROUP BY DATEPART(hh,DateTimeStamp)

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2002-12-09 : 13:24:45
Alternate.

SELECT
datediff(hh,dateadd(dd,datediff(dd,0,DateTimeStamp),0),DateTimeStamp) As HOUR, COUNT(*) AS TOTAL
FROM Tbl
GROUP BY
datediff(hh,dateadd(dd,datediff(dd,0,LastAccessed),0) ,LastAccessed)

Go to Top of Page
   

- Advertisement -