-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[DM_RISCHIO_DETTAGLIO_pre_selective]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    -- Insert statements for procedure here
	TRUNCATE TABLE C6MART.RISCHIO_DETTAGLIO
	DECLARE @ID_ELAB INT
	DECLARE @TIPO_ELAB VARCHAR(1)
	SET @ID_ELAB = C6MART.GETIDELAB()
	SET @TIPO_ELAB = C6MART.GETTIPOELAB()
	SELECT 
---- INFO TABELLA PER GESTIONE ERRORE
--		'RISCHIO_DETTAGLIO' AS TABLENAME,
--		'RETE - COD_FISCALE - COD_PROD' AS KEYCOLUMN,
--		PROMETEIA_DETT.RETE + ' - ' + PROMETEIA_DETT.CODICEFISCALE + ' - ' + PROMETEIA_DETT.CODICEPRODOTTO AS KEYVALUE,
---- FINE INFO TABELLA PER GESTIONE ERRORE
		PROMETEIA_DETT.RETE AS RETE,
		PROMETEIA_DETT.CODICEFISCALE AS COD_FISCALE,
		PROMETEIA_DETT.PORTAFOGLIO AS COD_AGGREG,
		PROMETEIA_DETT.CODICEPRODOTTO AS CHIAVE_PRODOTTO,
		PROMETEIA_DETT.VARASSOLUTO AS VAR_ASSOLUTO_PTF,
		PROMETEIA_DETT.VARPERCENTUALE AS VAR_PERC_PTF,
		PROMETEIA_DETT.CVARASSOLUTO AS CVAR_ASSOLUTO_PTF,
		PROMETEIA_DETT.CVARPERCENTUALE AS CVAR_PERC_PTF,
		PROMETEIA_DETT.MCVAR AS MCVAR,
		PROMETEIA_DETT.MCVARP AS MCVARP,
		PROMETEIA_DETT.TIPOCOPERTURA AS TIPO_COPERTURA,
		PROMETEIA_DETT.CTVNOMINALE AS CTV_AGGREG,
		PROMETEIA_DETT.PIAZZA AS MERCATO_CONTRATT,
		PROMETEIA_DETT.CODVAL AS DIV_CONTRATT,
		@ID_ELAB AS ID_ELAB,
		@TIPO_ELAB AS TIPO_ELAB
	FROM C6STAGING.PROMETEIA_DETT
END