日期:2014-05-19  浏览次数:20482 次

怎样在查询中判断某列为空值?
如题。请教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”是用在逻辑意义上的