Ignoring a NULL parameter in T-SQL

后端 未结 10 956
余生分开走
余生分开走 2020-12-03 01:40

I want to be able to pass in a list of parameters, and ignore the ones which are NULL. So that the query is in effect pretending that the filter isn\'t there and ignoring it

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 01:53

    If the Thing (column value) is also Nullable, then use the foll. approach:

    WHERE COALESCE(Thing,'')=COALESCE(@thing,Thing,'')
    

提交回复
热议问题