-- Schema: C6StagingPeriodico
-- Stored Procedure: REPTRIM_W6CLIREP_B







  
  
  
CREATE     procedure [C6StagingPeriodico].[REPTRIM_W6CLIREP_B]  
AS 
BEGIN  

exec [C6StagingPeriodico].[RP_W6LogBatch] 'Replica W6CLIREP_B'

TRUNCATE TABLE [C6MartPeriodico].[W6CLIREP_B]


INSERT INTO [C6MartPeriodico].[W6CLIREP_B]
           ( [FLGCLI]
      ,[FLGBL]
      ,[TIPOELA]
      ,[DTTRIM]
      ,[rete]
      ,[codfis]
      ,[piva]
      ,[codman]
      ,[CODFID]
      ,[CODAGE]
      ,[CODABI]
      ,[termid]
      ,[anno]
      ,[prog]
      ,[quote]
      ,[CTV]
      ,[codconf]
      ,[rubr]
      ,[custgar]
      ,[cod_interno]
      ,[codana]
      ,[FLAGPCT]
      ,[codprod]
      ,[cod_sottoprodotto]
      ,[cod_isin]
      ,[codlinea]
      ,[tipoptf]
      ,[area]
      ,[progetto]
      ,[codprj]
      ,[chiave_prodotto_terzi]
      ,[assetterzi]
      ,[famprodt]
      ,[intermediario]
      ,[codiceadeguatezza]
      ,[cod_maf]
      ,[conto]
      ,[numpolizza]
      ,[position_id]
      ,[PREFSOST]
      ,[FLAGAMB]
      ,[FLAGSOC]
      ,[FLAGGOV])
SELECT 
    TRIM([FLGCLI]) AS FLGCLI,
    TRIM([FLGBL]) AS FLGBL,
    TRIM([TIPOELA]) AS TIPOELA,
    [DTTRIM] AS DTTRIM,
    TRIM([rete]) AS rete,
    TRIM([codfis]) AS codfis,
    TRIM([piva]) AS piva,
    TRIM([codman]) AS codman,
    TRIM([CODFID]) AS CODFID,
    TRIM([CODAGE]) AS CODAGE,
    TRIM([CODABI]) AS CODABI,
    TRIM([termid]) AS termid,
    [anno] AS anno,
    [prog] AS prog,
    [quote] AS quote,
    [CTV] AS CTV,
    TRIM([codconf]) AS codconf,
    TRIM([rubr]) AS rubr,
    TRIM([custgar]) AS custgar,
    TRIM([codint]) AS codint,
    TRIM([codana]) AS codana,
    TRIM([FLAGPCT]) AS FLAGPCT,
    TRIM([codprod]) AS codprod,
    TRIM([subprod]) AS subprod,
    TRIM([isin]) AS isin,
    TRIM([codlinea]) AS codlinea,
    TRIM([tipoptf]) AS tipoptf,
    TRIM([area]) AS area,
    TRIM([progetto]) AS progetto,
    TRIM([codprj]) AS codprj,
    TRIM([keyprd]) AS keyprd,
    TRIM([assettrz]) AS assettrz,
    TRIM([famprd]) AS famprd,
    TRIM([interm]) AS interm,
    TRIM([codade]) AS codade,
    TRIM([codmaf]) AS codmaf,
    TRIM([conto]) AS conto,
    TRIM([numpol]) AS numpol,
    TRIM([posid]) AS posid,
    TRIM([PREFSOST]) AS PREFSOST,
    TRIM([FLAGAMB]) AS FLAGAMB,
    TRIM([FLAGSOC]) AS FLAGSOC,
    TRIM([FLAGGOV]) AS FLAGGOV
FROM 
    FSEI0.sfsei0.[fsei0_pdc].[w6clirep]

	DECLARE @DtTrim varchar(9);

SET @DtTrim = dbo.VerificaFestivo((SELECT MAX(dttrim) FROM [C6MartPeriodico].[W6CLIREP_B]));

update [C6MartPeriodico].[W6CLIREP_B]
set DTTRIM=@DtTrim




  exec [C6StagingPeriodico].[RP_W6LogBatch] 'Replica W6CLIREP_B'
  
END  
  
  
  
  
  
  
  
  
  

