|
本文重点讲解在SQL数据库开发中ISNULL函数的语法使用,并附用实例讲解!真正让大家体会到在实际开发中的妙用 ISNULL
使用指定的替换值替换 NULL。
语法: ISNULL ( check_expression , replacement_value )
参数:
check_expression:将被检查是否为NULL的表达式。check_expression 可以是任何类型的。
replacement_value:在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。
返回类型: 返回与 check_expression 相同的类型。
注释: 如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。
drop table #tmp1 drop table #tmp2 create table #tmp1 (id int, num int)
create table #tmp2 (id int, num int)
insert into #tmp1 values (1,0) insert into #tmp1 values (2,0) insert into #tmp1 values (3,0) insert into #tmp1 values (4,0) insert into #tmp1 values (5,0) insert into #tmp1 values (6,0) insert into #tmp1 values (7,0) insert into #tmp1 values (8,0) insert into #tmp1 values (9,0)
insert into #tmp2 values (1,8) insert into #tmp2 values (2,5)
/* update #tmp1 set num = num + IsNull((select case when num>=8 then 1 else 0 end from #tmp2 where #tmp2.id = #tmp1.id),0) */ update #tmp1 set num = num + (select case when num>=8 then 1 else 0 end from #tmp2 where #tmp2.num = #tmp1.num)
select * from #tmp1 select * from #tmp2
|