如果我使用 IN 运算符过滤 NULL 值和空格它不起作用为什么



我有一个像这样的表格表1(ID整数,名称VC,描述VC);此表包含 100 条记录。对于描述列,它有一些空格和空值我想消除描述值为 Null 或空格的行?

我以这种方式尝试过

select * from table1 where description not in('',NULL); //Displaying nothing
But
select * from table1 where description in('',NULL);// It is displaying all the rows which contains white spaces but not Nulls

我很困惑。IN 运算符也接受 varchar,如果我不使用 NOT,我会得到正确的结果,但如果我使用 NOt,为什么我没有得到。

提前谢谢..

试试这个:

select * from table1 where description not in('') and description is not null ;

你需要使用 IS NOT NULL 来比较 NULL 值

select * from table1 where description is not null and description <> ''

可以试试这个 - 这将类似于 c# .IsNull或Whitespace

从表 1 中选择 *,其中描述不为空,并且 LEN(修剪(描述)> 0)

因为 SQL "

IN" 条件有助于减少使用多个 SQL"OR" 条件的需要。

所以,写作:

description not in('',NULL);

它与以下情况相同:

!(description='' OR description is NULL)

写起来也一样:

!(description='') AND description is not NULL

最新更新