I'm executing a query that returns about 16000 rows. Running the straight SQL in MS SQL Server Manager returns the records in a few seconds. Running the same SQL in cfquery returns it in about the same time. The query is composed with a few variables coming from a function arguments. Letting the cfquery evaluate the variables also returns the query fast.
Why is it when I add cfqueryparam for the variables, and there are only 6 of them, the query runs for over an hour and then times out. The cfsqltype are *cf_sql_integer* and *cf_sql_timestamp*. As soon as I remove them, it's done and working.
OPTION (RECOMPILE)
in the query, which was enough to get the query planner to create a good plan. – user166390