I have a dynamic query that is just too large to put here. Safe to say that in it\'s current form it utilizes a CLR procedure to dynamically build joins based upon the numb
I had a similar problem. In the end, I removed the cached query plan with this command:
dbcc freeproccache([your plan handle here])
In order to get your plan handle, you can use the following query:
SELECT qs.plan_handle, a.attrlist, est.dbid, text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) est
CROSS APPLY (SELECT epa.attribute + '=' + convert(nvarchar(127), epa.value) + ' '
FROM sys.dm_exec_plan_attributes(qs.plan_handle) epa
WHERE epa.is_cache_key = 1
ORDER BY epa.attribute
FOR XML PATH('')) AS a(attrlist)
WHERE est.text LIKE '%standardHourRate%' and est.text like '%q__7%'and est.text like '%Unit Overhead%'
AND est.text NOT LIKE '%sys.dm_exec_plan_attributes%'
replacing the content of the 'like' clauses with appropriate pieces of your query.
You can see my whole issue at:
SQL Query Using Entity Framework Runs Slower, uses bad query plan