在一个视图中我想实现加法运算,其中在参加运算一个字段中有部分值显示为NULL,这样部分加法结果会显示不出来。我用CASE 语句将其为NULL的变为0,可是有错误。我该怎么办呢?如:
a1,a2,a3,a4为 int 型select a1,a2,a3,
case a4 when null then 0
else a1+a2+a4 end as a5
from table1
a4字段中部分值显示为null,这样写不对吗?
a1,a2,a3,a4为 int 型select a1,a2,a3,
case a4 when null then 0
else a1+a2+a4 end as a5
from table1
a4字段中部分值显示为null,这样写不对吗?
from table1
a1+a2+isnull(a4,0) as a5
from table1
使用指定的替换值替换NULL。
case a4 is null then 0
else a1+a2+a4 end as a5
from table1这样应该可以了。
要转换成合法的数据才能计算
case when a4 is null then 0
else a1+a2+a4 end as a5
from table1
from table1
select a1,a2,a3,(a1+a2+isNull(a4,0)) as a5
from table1
这样可以了。