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.
Related Contents:
- Simulating group_concat MySQL function in Microsoft SQL Server 2005?
- Insert results of a stored procedure into a temporary table
- SQL update query using joins
- How to update two tables in one statement in SQL Server 2005?
- Referring to a Column Alias in a WHERE Clause
- How to SELECT FROM stored procedure
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- SQL query to select dates between two dates
- Convert Month Number to Month Name Function in SQL
- The multi-part identifier could not be bound
- Create a date from day month and year with T-SQL
- How to avoid the “divide by zero” error in SQL?
- How important is the order of columns in indexes?
- Are there any disadvantages to always using nvarchar(MAX)?
- How to return multiple values in one column (T-SQL)?
- SET versus SELECT when assigning variables?
- Using the result of an expression (e.g. Function call) in a stored procedure parameter list?
- Getting result of dynamic SQL into a variable for sql-server
- conditional unique constraint
- Turn off constraints temporarily (MS SQL)
- How to print VARCHAR(MAX) using Print Statement?
- Difference between a User and a Login in SQL Server
- SQL statement to select all rows from previous day
- Get the week start date and week end date from week number
- Can a Check constraint relate to another table?
- How to find current transaction level?
- How to get difference between two rows for a column field?
- SQL – Subtracting a depleting value from rows
- Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement
- Pass table as parameter into sql server UDF
- Execute Stored Procedure from a Function
- How to Replace Multiple Characters in SQL?
- Execution sequence of Group By, Having and Where clause in SQL Server?
- varbinary to string on SQL Server
- SELECT FOR UPDATE with SQL Server
- How to insert multiple records and get the identity value?
- EXISTS vs JOIN and use of EXISTS clause
- Script to save varbinary data to disk
- SQL : in clause in stored procedure:how to pass values
- How to insert a blob into a database using sql server management studio
- Dynamic SQL to generate column names?
- separate comma separated values and store in table in sql server
- How to select date without time in SQL
- Best way to do nested case statement logic in SQL Server
- SQL Server 2005 ROW_NUMBER() without ORDER BY
- Measuring Query Performance : “Execution Plan Query Cost” vs “Time Taken”
- SQL, How to Concatenate results?
- When to use EXCEPT as opposed to NOT EXISTS in Transact SQL?
- How to find consecutive rows based on the value of a column?
- SQL Script to alter ALL Foreign Keys to add ON DELETE CASCADE