Expression
WHERE datediff(dd, senddate, @RunDate) > @CalculationInterval
will not be able to use the index in the senddate column due to the function on the LHS on senddate
To make a WHERE "SARGable" (that is, use an index), change it to an equivalent condition:
WHERE senddate < dateadd(dd, -@CalculationInterval, @RunDate)
[Thanks @Krystian Lieber for pointing out the wrong condition].
Mitch wheat
source share