select ABcnt=sum(ABcnt),ABcredit=sum(ABcredit) from
(
select count(*) as ABcnt,sum(credit) as ABcredit from A
union all
select count(*) as ABcnt,sum(credit) as ABcredit from B
)a
(
select count(*) as ABcnt,sum(credit) as ABcredit from A
union all
select count(*) as ABcnt,sum(credit) as ABcredit from B
)a
select Acnt+Bcnt as ABcnt ,Acredit+Bcredit as ABcredit from
(select count(*) as Acnt,sum(credit) as Acredit from #aa)aa left join
(select count(*) as Bcnt,sum(credit) as Bcredit from #bb)bb on 1=1