I am trying to use the over function to count the number of events which start between the start and end date of the current row for all rows. I.e. a concurrent counter. Ultimately I will be looking to find the Maximum Concurrent events per day or hour etc.
select FingerPrint
,StartDate
,EndDate
,Num_ConCurrent = count(FingerPrint) over (
partition by StartDate
order by StartDate
range between StartDate PRECEDING and EndDate following
)
from #File
group by FingerPrint
,StartDate
,Enddate
Unfortunately this does not appear to work. Whilst I know I could simply use a self join I thought there might be an alternative method with the over clause.
Any help much appreciated.
NB: Error Message
Msg 102, Level 15, State 1, Line 7 Incorrect syntax near 'StartDate'.