如果我使用 IN 运算符来过滤 NULL 值和空格 它不起作用 为什么? [英] If I use IN operator to filter NULL values and white spaces It is not working Why?

查看:47
本文介绍了如果我使用 IN 运算符来过滤 NULL 值和空格 它不起作用 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张像table1(id int,name VC,description VC);该表包含 100 条记录.对于 description 列,它有一些空格和空值我想消除描述值为 Null 或空格的行?

I have a table like table1(id int,name VC,description VC); This table contains 100s of records. For description column it has some white spaces and null values I want to eliminate the rows for which the description value is Null or whitespace?

我是这样试的

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,为什么我没有得到.

I am confused. IN operator accepts varchar also, I am getting correct result if I wont use NOT, but Why I am not getting If I use NOt.

提前致谢..

推荐答案

需要使用IS NOT NULL比较空值

you need to use IS NOT NULL to compare null values

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

这篇关于如果我使用 IN 运算符来过滤 NULL 值和空格 它不起作用 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆