In my SQL Server query, I am trying to get a 2 second data range:
DECLARE @runtime AS datetime SELECT @runtime = '2014-02-15 03:34:17' SELECT Application FROM commandcip WHERE commandname = 'RunTestCase' AND (createdate BETWEEN DATEADD(s, -1, @runtime) AND DATEADD(s, 1, @runtime))
This command works very slowly, it takes minutes, and the estimated cost of subtitles based on the performance analyzer is 2800.
On the other hand, if I calculate the range manually, the request will be very fast (Estimated subtitle cost = 0.5, request time <1 second):
SELECT Application FROM commandcip WHERE commandname = 'RunTestCase' AND createdate BETWEEN '2014-02-15 03:34:16' AND '2014-02-15 03:34:18'
I confirmed that both commands return the correct data. I confirmed that my DATEADD commands DATEADD returning the correct dates. I also tried getting DATEADD one step earlier (in separate variables @mindate , @maxdate ), but that didn't help.
How to speed up the first query without manually calculating the range?
source share