SqlServer_查询带有null的记录

本文探讨了SQL Server中字段的三种状态,特别是关于空值(NULL)的处理。推荐使用`IS NOT NULL`进行判断,因为`!= NULL`在默认情况下不会返回任何结果。同时,介绍了如何通过`SET ANSI_NULLS`开关在标准和非标准模式间切换,以使得`IS NOT NULL`和`!= NULL`变得等效。在不同的数据库访问方式下,如ODBC或OLEDB,`SET ANSI_NULLS`的默认设置可能影响查询行为,需要谨慎处理。
摘要由CSDN通过智能技术生成

字段的三种不同状态

select distinct status  from t_table
(NULL)
XXX
YYY

不同状态的记录数

select count(1) from t_table  35709
select count(1) from t_table where status  = 'XXX'      17579 XXX
select count(1) from t_table where status  = 'YYY'      4242  YYY
select count(1) from t_table where status  is null      13888 (NULL)
select count(1) from t_table where status  = null       0
select count(1) from t_table where status  is not null  21821 XXX+ YYY 
select count(1) from t_table where status  <> null      0
select count(1) from t_table where status  != null      0 

1

select count(1)  from t_table where status   != 'XXX'     4242   不含null值记录
select count(1)  from t_table where status   != 'YYY'     17579  不含null值记录
select count(1)  from t_table where status   != 'XXX' and  status   != 'YYY'   0    !=  不包含 null值的记录

2

select count(1) from t_table where status  in (select status  from t_table)                                   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值