一尘不染

IS NULL vs = NULL在where子句中+ SQL Server

sql

如何检查值IS NULL [or] = @param(@param为空)

前任:

Select column1 from Table1
where column2 IS NULL => works fine

如果我想将比较值(IS NULL)替换为@param。如何才能做到这一点

Select column1 from Table1
where column2 = @param => this works fine until @param got some value in it and if is null never finds a record.

如何实现?


阅读 135

收藏
2021-05-05

共1个答案

一尘不染

select column1 from Table1
  where (@param is null and column2 is null)
     or (column2 = @param)
2021-05-05