函数:isnull

问题:警告: 聚合或其他 SET 操作消除了 Nullcreate table tb
(
id int,
num int
)


insert into tb select 1,10
insert into tb select 1,20
insert into tb select 2,80
insert into tb select 2,null

select id,sum(num)
from tb
group by id

警告: 聚合或其他 SET 操作消除了 Null 值。

(2 行受影响)

解决方案:

select id,sum(isnull(num,0))
from tb
group by id

 

结论:

msdn说明:当 check_expression 为 NULL 时要返回的表达式。replacement_value 必须是可以隐式转换为 check_expresssion 类型的类型

isnull对int返回指定值,对text可返回指定值, 对datetime返回指定值。

 

posted on 2011-09-14 20:57  雨渐渐  阅读(363)  评论(0编辑  收藏  举报

导航