-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE c6stagingperiodico.sp_quadratura
	-- Add the parameters for the stored procedure here
AS
BEGIN
DROP TABLE if exists #excel
DROP TABLE if exists #txt
drop table if exists #differenze
drop table if exists [C6MartPeriodico].[anag_prelievi_excel_txt_differenze]
SELECT substring(cf,17,1)+ltrim(rtrim(substring(cf,1,16)))+substring(cf,18,4)+substring(cf,23,2)+substring(cf,26,2) as cf
into #txt
  FROM [C6MartPeriodico].[anag_prelievi_txt]
  select rete+ltrim(rtrim(codfis))+dtavmon as cf2 
into #excel 
from [C6MartPeriodico].[anag_prelievi_excel]
select * 
into #differenze
from(
select cf from #txt
except
select cf2 from #excel
) t
select cf as CodiceFiscale
into [C6MartPeriodico].[anag_prelievi_excel_txt_differenze]
from #differenze
where cf not like '%00000000000%'
select * from [C6MartPeriodico].[anag_prelievi_excel_txt_differenze]
END