首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎样在查询中判断某列为空值?该怎么处理

2012-01-07 
怎样在查询中判断某列为空值?如题。请教isnull的具体用法。可否举个例子[解决办法]select *from 表名where

怎样在查询中判断某列为空值?
如题。请教is   null的具体用法。
可否举个例子

[解决办法]
select *
from 表名
where 字段名 = null

[解决办法]
--不能用=null来判断字段值是否为空,可以看一下例子:


create table #t (f1 varchar(100),f2 varchar(100))
insert into #t select 'aaa ', '111 '
insert into #t select 'bbb ',null

--这是对的
select *
from #t
where f2 is null


--这样的查询结果是不对的
select *
from #t
where f2 = null


drop table #t

[解决办法]
判断某列的值是否为null,使用is null,例子见1楼

另外,isnull()函数是用来将null转换为需要的值,例如,select isnull(colname, '123 ') from table1

[解决办法]
where 字段名 is null
[解决办法]
“=”是用在实际的对象分量上的,而“IS”是用在逻辑意义上的

热点排行