-- Schema: C6MartPeriodico
-- Stored Procedure: DM_CLIENTI_CON_RNA_ALTO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6MartPeriodico].[DM_CLIENTI_CON_RNA_ALTO]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

 	DECLARE @ID_ELAB INT
	DECLARE @TIPO_ELAB VARCHAR(1)
	DECLARE @Rna DECIMAL(19,3)
	SET @Rna = CAST(dbo.getParametro('PERCMAXRISORSENA') AS DECIMAL(19,3)) * 0.01


    
	SET @ID_ELAB = C6MartPeriodico.GETIDELAB()
	SET @TIPO_ELAB = C6MartPeriodico.GETTIPOELAB()
		
	TRUNCATE TABLE [C6MartPeriodico].[CLIENTI_CON_RNA_ALTO]

	INSERT INTO [C6MartPeriodico].[CLIENTI_CON_RNA_ALTO]
           (Rete, 
			CodicePB,
			CodiceFiscale, 
			Percentuale, 
			DataCalcolo,
			ID_ELAB,
			TIPO_ELAB)
	SELECT 
		Rete, 
		CodicePB,
		CodiceFiscale, 
		Percentuale, 
		DataCalcolo,
		@ID_ELAB AS ID_ELAB,
		@TIPO_ELAB AS TIPO_ELAB
	FROM C6StagingPeriodico.CLIENTI_CON_RNA
	WHERE Percentuale > @Rna 
END

