How can I rate this request?
This query will give me error: Msg 156, Level 15, State 1, Line 10 Incorrect syntax next to the "where" keyword.
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
0
a source to share
2 answers
You need to specify your derived table with a name eg. DT1. Here I have reformatted the SQL text to my personal taste :) to make it easier to read:
select DT1.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
) AS DT1
where DT1.OrderNumber=@order
+2
a source to share