Ignoring a NULL parameter in T-SQL

后端 未结 10 950
余生分开走
余生分开走 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条回答
  •  情话喂你
    2020-12-03 02:06

    I would handle it this way.

    WHERE Thing = ISNULL(@Thing, Thing)
    

    If you're just using the parameter as a filter on the where clause, this will work very well. It will ignore the parameter if it is null.

提交回复
热议问题