Alternative to using local variables in a where clause

后端 未结 4 1654
清歌不尽
清歌不尽 2021-01-24 07:24

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

4条回答
  •  清歌不尽
    2021-01-24 07:38

    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

提交回复
热议问题