问题描述
|
select a.cust_xref_id,a.est_hour,a.phone_nbr as number,a.credit_calls,a.credit_rpcs,b.sdp_calls
from #temp0 a
full outer join #temp2 b
on a.cust_xref_id = b.sdp_cust_xref_id
and a.est_hour = b.sdp_hour
and a.phone_nbr = b.sdp_phone
当通过联接在两个表中都不存在数据时,是否有一种方法可以从表b中获得关于sdp_cust_xref_id
,sdp_hour
和sdp_phone
的数据?如果确实存在b.sdp_calls,则列值为空。
解决方法
我再读了几次,我想我知道你想要什么。尝试这个。如果它们在表a中为
NULL
,它将为您提供表b中的值:
select COALESCE(a.cust_xref_id,b.sdp_cust_xref_id) as cust_xref_id,COALESCE(a.est_hour,b.spd_hour) as est_hour,COALESCE(a.phone_nbr,b.spd_phone) as number,a.credit_calls,a.credit_rpcs,b.sdp_calls
from #temp0 a
full outer join #temp2 b
on a.cust_xref_id = b.sdp_cust_xref_id
and a.est_hour = b.sdp_hour
and a.phone_nbr = b.sdp_phone