I have a query that has a where clause built using a number of local variables, This however is painfully slow. Below is a rough example as I don\'t have access to the query cur
It gets messy and can lead to a new set of problems but you might want to evaluate converting this over to dynamic SQL. Basically you construct your where clause at run time based on which parameters actually have (non wildcard) values in them.
This is one of the best dynamic SQL write-ups I have found: http://www.sommarskog.se/dynamic_sql.html
And here is another where he specifically addresses dynamic where clauses: http://www.sommarskog.se/dyn-search-2005.html