This query give me error:Msg 156, Level 15, State 1, Line 10 Incorrect syntax near the keyword 'where'.
declare @date1 datetime,@date2 datetime , @COUNT INT , @countgap int, @order int
seLECT @date1='2009-05-11' , @date2 = '2009-05-12'
seLECT @countgap = 30 , @COUNT = 0, @order=23
select VisitingCount from (
select count(page) as VisitingCount,
(datepart(hour,Date)*60+datepart(minute,Date))/@countgap as OrderNumber
from scr_SecuristLog
where Date between @date1 and @date2
GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/@countgap) where OrderNumber=@order