isnull的用法sqlserver把两个sql查询语句查询出来的两张表合并成⼀张表第⼀个sql语句
select companyname gsmc,zb zhibiao
from t_gsndzb left join t_companycode
on t_gsndzb.gsbh=t_companycodepanyid
查询结果:
第⼆个sql语句
SELECT min(companyname) gsmc,cast(round(sum(t_xstj.hsje)/10000,2)  as  numeric(20,2))  ndje FROM t_xstj left join t_companycode
on t_companycodepanyid = t_xstj.gsbh
where datediff(year,sj,getdate())=0group by gsbh
查询结果:
合并成⼀张表的语句:
select isnull(a.gsmc,b.gsmc) gsmc,isnull(a.zhibiao,0) zhibiao,isnull(b.ndje,0) ndje
from (
--第⼆个表查询结果--
select companyname gsmc,zb zhibiao
from t_gsndzb left join t_companycode
on t_gsndzb.gsbh=t_companycodepanyid
)
A FULL JOIN (
--第⼆个表查询结果--
SELECT min(companyname) gsmc,
cast(round(sum(t_xstj.hsje)/10000,2)  as  numeric(20,2))  ndje
FROM t_xstj left join t_companycode
on t_companycodepanyid = t_xstj.gsbh
where datediff(year,sj,getdate())=0group by gsbh
) b
on a.gsmc=b.gsmc
结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。