I have a table with about 1.5 million rows with date_run is indexed non cluster. Query #1 takes 0 second to finish and query #2 takes 3 seconds. Can someone please explain why query #2 runs slower. I also included execution plans for both. Sql server version 2014.
query #1
select avg14gain
from stocktrack
where
date_run >= '2013-3-21'
and date_run < '2013-3-22'
Valid XHTML http://biginkz.com/Pics/DateHardCoded.jpg.
query #2
declare @today date
declare @yesterday date
set @today='2013-3-22'
set @yesterday='2013-3-21'
select avg14gain
from stocktrack
where
date_run >= @yesterday
and b.date_run <@today