Sergiy (5/24/2016)
This is exactly the problem.Make both PK's non-clustered and create a new clustered index on [start_time].
That's what you've got:
WHERE (dateadd(dd,0, datediff(dd,0,b.start_time))) >= @StartDate
AND (dateadd(dd,0, datediff(dd,0,b.start_time))) <= @EndDate
I assume @StartDate and @EndDate never contain a time portion.
And you intend to select all records with [start_time] during the day indicated by @EndDate.If this is correct then your clause should look like that:
WHERE @StartDate <= b.start_time
AND b.start_time < DATEADD(dd, 1, @EndDate)
Thanks for for advice, both PK's have been changed to non-clustered, [start_time] has been set to clustered index and updated the WHERE clause.
However, the query runs slower now. SQL Plan is attached.