Add OPTION (RECOMPILE)
to the end of the query.
SQL Server doesn’t “sniff” the values of the variables so you will be getting a plan based on guessed statistics rather than one tailored for the actual variable values.
Add OPTION (RECOMPILE)
to the end of the query.
SQL Server doesn’t “sniff” the values of the variables so you will be getting a plan based on guessed statistics rather than one tailored for the actual variable values.