I have used two methods to get around parameter sniffing issues in the past:
1) Use WITH RECOMPILE
2) Reassign parameter values to local variables and use those instead of the parameters
From what I understand, the end result of both of these is the same - a new execution plan that is optimized for the current query/params is created and used.
If this is true, are there any differences between these two methods or are they essentially the same? Is one preferable over the other?
OPTIMIZE FOR (UNKNOWN). The statement is compiled without looking at specific parameter values at all (except if the statement ends up getting a recompile anyway in which case the values of the variable will be used) – Martin Smith Jun 28 '12 at 16:27