I have a recursive query which executes very fast if the WHERE clause contains a constant but becomes very slow if I replace the constant with a parameter havin
WHERE
This could be the worse suggestion ever, but have you considered creating a sproc to create your query as a string and execute it using sp_executesql?
I know nothing about the caching behaviour of SQL executed by sp_executesql, it was just the first thing to pop into my head.