where子句是否为null而不是

时间:2014-06-18 15:32:19

标签: sql tsql

我对where子句有疑问。我希望将列的"is null""<>"功能放在一起。写了这样的东西,但它删除了t1.column1= test and is null的行。我想只删除测试。

where (t1.column1 is null 
or t2.column1 is null
or t2.column2 is null)
and t1.column1 <> 'test'

提前致谢。

4 个答案:

答案 0 :(得分:1)

你可以尝试:

WHERE  (   t1.column1 != 'test'
       AND (t2.column1 IS NULL OR t2.column2 IS NULL)
       )
    OR t1.column1 IS NULL

获得理想的结果。

答案 1 :(得分:0)

你可能需要打破每一个:

where (t1.column1 is null and t1.column1 <> 'test') 
or (t2.column1 is null  and t2.column1 <> 'test')
or (t2.column2 is null  and t2.column2 <> 'test')  

或者每种情况需要的任何标准......

答案 2 :(得分:0)

你永远无法满足这个条件 这将永远是假的

t1.column1 is null and t1.column1 <> 'test'

如果是&lt;&gt; 'test'然后它不是空的

任何与null的比较都会返回false 所有这些都将返回假 null = null
null&lt;&gt;空
'value'= null
'价值'&lt;&gt; null

偶数(Not('value'= null))将返回false

所以如果t1.column1 = null那么你就有了 true和false = false

答案 3 :(得分:0)

Select t1.[Column1], t2.[Column2]
From MyTable t1
INNER JOIN MyTable t2
On t1.userid = t2.userid
where t1.[column1] is null Or t1.[column1] = ''
or t2.[column1] is null Or t2.[column1] = ''
or t2.[column2] is null Or t2.[column2] = ''
and t1.[column1] <> 'test'
相关问题