WHERE IS NULL, IS NOT NULL or NO WHERE clause depending on SQL Server parameter value

前端 未结 7 2289
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 22:57

I have a stored procedure in SQL Server 2000 that performs a search based on parameter values. For one of the parameters passed in, I need a different WHERE cla

7条回答
  •  遥遥无期
    2020-12-02 23:28

    You could just do something like this:

    SELECT *
    FROM foo
    WHERE (@param = 0 AND MyColumn IS NULL)
    OR (@param = 1 AND MyColumn IS NOT NULL)
    OR (@param = 2)
    

    Something like that.

提交回复
热议问题