Relative Content

Tag Archive for sqlsql-serverdynamic-sqlsql-execution-planparameter-sniffing

Dynamic sql with order by difference but with one execution plan

I have some dynamic sql that generates the below CTE. The dynamic SQL generates different order by statements depending on the parameter in the SP. Here you can see it was Name, ORDER BY t.Name ASC. I believe this creates a new plan for each sort order that is different. Is there a way to only create one plan for this query regardless of the order by?