-- Schema: C6MartPeriodicoImmobiliare
-- Stored Procedure: sp_caricaBlacklist




-- Stored procedure

CREATE PROCEDURE [C6MartPeriodicoImmobiliare].[sp_caricaBlacklist]
	
AS
BEGIN


 Declare @dtTrime as decimal;  
 set @dtTrime=convert(decimal,c6martperiodico.gettrimestre2(getdate(),0))  

 truncate table C6MartPeriodicoImmobiliare.blacklist

 insert into C6MartPeriodicoImmobiliare.blacklist
 select
	   [Rete]
      ,case when codman <> '' then 'FF@' + CODMAN
	  when len(codfis)=11 then NULL else codfis end as codiceFiscale
	  ,case when LEN(codfis) =11 and codman='' then codfis else NULL end as Piva
	  ,case when codman<>'' then codman else NULL end as Codman
		,case when tipolett = '2' then 'BLACKLIST RFA MINUS CLIENTE SEI E IMMOBILIARE' 
			when tipolett = '1' then 'BLACKLIST RFA MINUS CLIENTE IMMOBILIARE' END AS  DescrErr
      ,getdate() as [DataIns]
     -- ,1 as [Bloccato]
from c6stagingPeriodico.wseidc 
where dttrim = @dtTrime and (tipolett='2' or TIPOLETT='1')

exec [C6MartPeriodicoImmobiliare].[Blacklist_Blocco_Tabellone] 'blocco' --aggiorna tabellone

END



