-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6MartPeriodico].[DM_ANAG_CLIENTI_PREV_pre_selective]
AS
BEGIN
	SET NOCOUNT ON;
   	DECLARE @ID_ELAB INT
	DECLARE @TIPO_ELAB VARCHAR(1)
	SET @ID_ELAB = C6MartPeriodico.GETIDELAB()
	SET @TIPO_ELAB = C6MartPeriodico.GETTIPOELAB()
	TRUNCATE TABLE C6MARTPERIODICO.ANAG_CLIENTI_PREV;
	INSERT INTO C6MartPeriodico.[ANAG_CLIENTI_PREV]
           ([RETE]
           ,[COD_FISCALE]
           ,[STATO_LAVORATIVO]
           ,[PROFESSIONE]
           ,[CAT_PROFESSIONALE]
           ,[DATA_INIZIO]
           ,[DATA_FINE]
           ,[RETRIB_LORDA]
           ,[PROFESSIONE_SEC]
           ,[CAT_PROFESSIONALE_SEC]
           ,[DATA_INIZIO_SEC]
           ,[DATA_FINE_SEC]
           ,[RETRIB_LORDA_SEC]
           ,[PROFESSIONE_PREC]
           ,[CAT_PROFESSIONALE_PREC]
           ,[DATA_INIZIO_PREC]
           ,[DATA_FINE_PREC]
           ,[RETRIB_LORDA_PREC]
           ,[RICONGIUNZIONE]
           ,[ID_ELAB]
           ,[TIPO_ELAB])
	SELECT 
		SUBSTRING(ALL_CF_PB.RETE_PB,1,1) AS RETE,
		SUBSTRING(ALL_CF_PB.CODICE_FISCALE,1,16) AS COD_FISCALE,
		NULL AS  STATO_LAVORATIVO,
		NULL AS  PROFESSIONE,
		NULL AS  CAT_PROFESSIONALE,
		NULL AS  DATA_INIZIO,
		NULL AS  DATA_FINE,
		NULL AS  RETRIB_LORDA,
		NULL AS  PROFESSIONE_SEC,
		NULL AS  CAT_PROFESSIONALE_SEC,
		NULL AS  DATA_INIZIO_SEC,
		NULL AS  DATA_FINE_SEC,
		NULL AS  RETRIB_LORDA_SEC,
		NULL AS  PROFESSIONE_PREC,
		NULL AS  CAT_PROFESSIONALE_PREC,
		NULL AS  DATA_INIZIO_PREC,
		NULL AS  DATA_FINE_PREC,
		NULL AS  RETRIB_LORDA_PREC,
		NULL AS  RICONGIUNZIONE,
		@ID_ELAB AS ID_ELAB,
		@TIPO_ELAB AS TIPO_ELAB
	FROM C6STAGINGPERIODICO.ALL_CF_PB
END