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)
 help! better performance... statement help needed!

Author  Topic 

thotef
Starting Member

3 Posts

Posted - 2009-03-06 : 07:57:06
Hi there!

I´m using this sql-statement now and it works fine but seems to be a bit slow when the amount of data is increased (of course it should be slower but not that much slower as I can see it).

This is what I use today:

SELECT DISTINCT { fn HOUR(Date_Time) } AS myHour, COUNT(*) AS NrOfHits FROM SmsGenEvents WHERE Department IS NOT NULL GROUP BY { fn HOUR(Date_Time) } ORDER BY { fn HOUR(Date_Time) }

The result is:

0 10
6 30
7 1861
8 31070
9 35463
10 49312
11 48244
12 24164
13 50717
14 34689
15 51412
16 25885
17 3191
18 1530
19 1096
20 942
21 393
22 181
23 108

Can this be done in a better way?
Any suggestions are welcome and I will performancetest everyone of them that will give me the same result and post back what I figured out!

Thank You in advance! // TT

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-06 : 08:36:48
Replace all odbc calls with DATEPART(HOUR, Date_Time)



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

- Advertisement -