CREATE procedure [C6StagingPeriodico].[REPTRIM_WSEIPS]  
AS 
BEGIN  
exec [C6StagingPeriodico].[RP_W6LogBatch] 'Replica WSEIPS'
TRUNCATE TABLE [C6StagingPeriodico].[WSEIPS]
INSERT INTO [C6StagingPeriodico].[WSEIPS]
           ([RETE]
           ,[DTTRIM]
           ,[CODFIS]
           ,[CODANA]
           ,[CODMAN]
           ,[CODAGE]
           ,[INTEST]
           ,[CODCONF]
           ,[SUBPROD]
           ,[DTLETT]
           ,[SEX]
           ,[INDIR]
           ,[CAP]
           ,[CITTA]
           ,[PROV]
           ,[NAZION]
           ,[PRESSO]
           ,[TIPCONTR])
SELECT [RETE]
      ,[DTTRIM]
      ,[CODFIS]
      ,[CODANA]
      ,[CODMAN]
      ,[CODAGE]
      ,[INTEST]
      ,[CODCONF]
      ,[SUBPROD]
      ,[DTLETT]
      ,[SEX]
      ,[INDIR]
      ,[CAP]
      ,[CITTA]
      ,[PROV]
      ,[NAZION]
      ,[PRESSO]
      ,[TIPCONTR]
  FROM FSEI0.sfsei0.[fsei0_pdc].[wseips]
  UNION
  SELECT [RETE]
      ,[DTTRIM]
      ,[CODFIS]
      ,[CODANA]
      ,[CODMAN]
      ,[CODAGE]
      ,[INTEST]
      ,[CODCONF]
      ,[SUBPROD]
      ,[DTLETT]
      ,[SEX]
      ,[INDIR]
      ,[CAP]
      ,[CITTA]
      ,[PROV]
      ,[NAZION]
      ,[PRESSO]
      ,[TIPCONTR]
  FROM FSEI0.sfsei0.[fsei0_pdc].[w6dbps]
  exec [C6StagingPeriodico].[RP_W6LogBatch] 'Replica WSEIPS'
END