I'm debugging a parameter sniffing issue in SQL Server 2014.
My application performs a query that along the lines of: (drastically reduced for simplicity)
SELECT somefields FROM MyTable Where anotherField = @myParameter
Where @myParameter is added through the command.Parameters.Add()
method, this query takes too long to run and times out.
When trying to replicate the issue, I went to SSMS and tried the following query:
DECLARE @myParameter int = 10 --same value as in the code
SELECT somefields FROM MyTable Where anotherField = @myParameter
And the query runs fast with a different execution plan from the code.
I want to try some tweaks to the query to see if I can improve my code's execution plan, but I need a ways to make SSRS behave the way my code does.
How can I write my query in SSRS, so that SQL Server calculates the execution plan in the same way it does for my application?