-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6MartPeriodico].[RP_DM_BONIFICA_DTRIF0_TSCABP]
AS
BEGIN
select *
into #dtrif_zero
from C6StagingPeriodico.TSCABP t where dtrif=0 
select distinct rete,CODAREA,CODPROG,CODFIS,CODCONF,DTRIF
into #dtrif_tcptab
from C6stagingPeriodico.tcptab
where rete+codfis+CODPROG+codconf in (select rete+CODFIS+codprog+codconf from #dtrif_zero)
update a
set a.dtrif=b.dtrif
from C6StagingPeriodico.TSCABP a
inner join #dtrif_tcptab b on a.rete=b.RETE 
and
a.codfis=b.codfis and
a.CODPROG=b.CODPROG and
a.CODCONF=b.CODCONF and
a.CODAREA=b.CODAREA 
where a.dtrif=0
END