-- Stored procedure
CREATE PROCEDURE [C6MartPeriodico].[sp_caricaBlacklist_RFAMinus]
AS
BEGIN
 Declare @dtTrime as decimal;  
 set @dtTrime=convert(decimal,c6martperiodico.gettrimestre2(getdate(),0))  
 insert into c6martPeriodico.ExcludedList
 select
	   [Rete]
      ,case when codman <> '' then 'FF@' + CODMAN else codfis end as codiceFiscale
      ,case when tipolett = 0 then 'BLACKLIST RFA=0' 
			when tipolett = 6 then 'BLACKLIST RFA MINUS CLIENTE SEI' 
			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
 insert into c6martPeriodico.ExcludedList
 select
	   [Rete]
      ,case when codman <> '' then 'FF@' + CODMAN else codfis end as CODFIS
      ,'BLACKLIST PROFILO SCADUTO' as DescrErr
      ,getdate() as [DataIns]
      ,1 as [Bloccato]
from c6stagingPeriodico.wseips
where dttrim = @dtTrime
END