• Try adding OPTION (RECOMPILE) to the second query or use sp_executesql with parameters to do the comparison.

    SQL Server uses different approach to estimate cardinality when you use parameters or constants than when you use variables. The value of the variables are not known during compilation time.

    --

    AMB