I need to get the total from two stored procedures. How could I add icnt + ncnt = tcnt to the below query or should I just sum icnt + ncnt and put the results into a separate table? Here's the stored procedure.
Truncate table iclaims
insert iClaims
Select Sort='1',Reg='NAT', Region='0', Area='00', Dist = '000', Doc = '000', convert(char,b.mnth_endt,1) as DowrDt, iCnt, tCnt, rpt='1'
From
(select mnth_endt, sum(zip_count) as iCnt
from [dbo].[iClaimsTemp]
where typ_of_actn='a' and abap_prc_cd NOT IN('y','s') and Bicnum IN('002','010') and inet_ind = '1'
--where INET_IND <> 'N' and (bicnum = '002' or bicnum = '202' or bicnum = '303' or bicnum = '304') and reg is not null and area is not null
Group by mnth_endt
)a
right join
(select mnth_endt, sum(zip_count) as nCnt
from [dbo].[iClaimsTemp]
Where typ_of_actn = 'a' and Bicnum = '002' and inet_ind = 'n' and abap_prc_cd NOT IN('y','s')
--where (bicnum = '002' or bicnum = '202' or bicnum = '303' or bicnum = '304') and reg is not null and area is not null
Group by mnth_endt
)b
on b.mnth_endt = a.mnth_endt
Truncate table iclaims
insert iClaims
Select Sort='1',Reg='NAT', Region='0', Area='00', Dist = '000', Doc = '000', convert(char,b.mnth_endt,1) as DowrDt, iCnt, tCnt, rpt='1'
From
(select mnth_endt, sum(zip_count) as iCnt
from [dbo].[iClaimsTemp]
where typ_of_actn='a' and abap_prc_cd NOT IN('y','s') and Bicnum IN('002','010') and inet_ind = '1'
--where INET_IND <> 'N' and (bicnum = '002' or bicnum = '202' or bicnum = '303' or bicnum = '304') and reg is not null and area is not null
Group by mnth_endt
)a
right join
(select mnth_endt, sum(zip_count) as nCnt
from [dbo].[iClaimsTemp]
Where typ_of_actn = 'a' and Bicnum = '002' and inet_ind = 'n' and abap_prc_cd NOT IN('y','s')
--where (bicnum = '002' or bicnum = '202' or bicnum = '303' or bicnum = '304') and reg is not null and area is not null
Group by mnth_endt
)b
on b.mnth_endt = a.mnth_endt