Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AVG Hourly Timestamp Count in SQL Server 2005 - Syntax Error 1

Status
Not open for further replies.

larrydavid

Programmer
Jul 22, 2010
174
0
0
US
Hello,

I have this statement which is returning correct data:

Code:
SELECT COUNT(*) count FROM CSDBBRDFC001.Hope.dbo.RealTimeProd    
		WHERE Timestamp >= CONVERT(DATETIME, '2011-02-07 00:00:00', 120) AND     
		Timestamp <= CONVERT(DATETIME, '2011-02-08 00:00:00', 120)   
		GROUP BY DATEADD(hour, DATEDIFF(hour, 0, Timestamp), 0)

Then I am trying to get the AVG in this approach:
Code:
SELECT AVG(count) FROM 
(     
		SELECT COUNT(*) count FROM ABCDEFG.Test.dbo.TestData    
		WHERE Timestamp >= CONVERT(DATETIME, '2011-02-07 00:00:00', 120) AND     
		Timestamp <= CONVERT(DATETIME, '2011-02-08 00:00:00', 120)   
		GROUP BY DATEADD(hour, DATEDIFF(hour, 0, Timestamp), 0)     
)

And I keep getting this:
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.

I've been pulling what little hair I have left for the past couple of hours and cannot figure out what the problem is. If someone could please help me I would really, truly appreciate it.

Thanks,
Larry
 
Ohhhh, thanks Mark. You saved my last two hairs. Much obliged. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top