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.
More Related Contents:
- Add a column with a default value to an existing table in SQL Server
- Simulating group_concat MySQL function in Microsoft SQL Server 2005?
- How can I do an UPDATE statement with JOIN in SQL Server?
- The multi-part identifier could not be bound
- Fastest way to update 120 Million records
- Can a Check constraint relate to another table?
- Is it possible to select sql server data using column ordinal position
- How to find current transaction level?
- How to insert multiple records and get the identity value?
- How to Replace Multiple Characters in SQL?
- How can a LEFT OUTER JOIN return more records than exist in the left table?
- EXISTS vs JOIN and use of EXISTS clause
- “select * from table” vs “select colA, colB, etc. from table” interesting behaviour in SQL Server 2005
- Dynamic SQL to generate column names?
- SQL comma-separated row with Group By clause
- Column name or number of supplied values does not match table definition
- How to split string using delimiter char using T-SQL?
- SQL Server PIVOT perhaps?
- How to find consecutive rows based on the value of a column?
- Should I use SQL_Variant data type?
- SQL server select distinct rows using most recent value only
- Script to save varbinary data to disk
- Measuring Query Performance : “Execution Plan Query Cost” vs “Time Taken”
- How to select date without time in SQL
- What is the internal representation of datetime in sql server?
- Eliminate and reduce overlapping date ranges
- SQL Server 2005 – Export table programmatically (run a .sql file to rebuild it)
- SQL Sort Order with Null values last
- Insert all values of a table into another table in SQL
- When to use EXCEPT as opposed to NOT EXISTS in Transact SQL?