0

我的查询中有 2 个临时表,我正在尝试添加 2 个字段。问题有时是第二个临时表结果为“NULL”值,然后当我将 2 个字段相加时,我得到一个“NULL”值:

#1 :  100
#2 :  NULL

select 
@tm as tm
,'Sales' = (a.Sales + b.Sales)
from #1 a
left join #2 b
on a.tm = b.tm

结果:

tm  Sales
12  NULL
4

1 回答 1

0

add COALESCE,一个值可能为空,

select  @tm as tm,
       'Sales' = (COALESCE(a.Sales, 0) + COALESCE(b.Sales,0))
from   #1 a
       left join #2 b on a.tm = b.tm
于 2013-04-04T06:47:08.627 回答