I have a number of days variable which I want to compare against a datetime column (senddate) .
Im currently doing this :
DECLARE @RunDate datetime =
The expression
WHERE datediff(dd, senddate, @RunDate) > @CalculationInterval
won't be able to use an index on the senddate
column, because of the function on the column senddate
In order to make the WHERE
clause 'SARGable' (i.e. able to use an index), change to the equivalent condition:
WHERE senddate < dateadd(dd, -@CalculationInterval, @RunDate)
[Thanks to @Krystian Lieber, for pointing out incorrect condition ].