-- Schema: C6Mart
-- Stored Procedure: PL_D_S151ProfiloDiRischio


-- =============================================
-- Author:		<Alessandro Tringali>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[PL_D_S151ProfiloDiRischio]
	-- Add the parameters for the stored procedure here
	@Rete char(1), 
	@CodiceFiscale varchar(16)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @varBF DECIMAL(12,2)
	DECLARE @coperturaBF DECIMAL(12,2)
	DECLARE @codiceProfilo SMALLINT
	DECLARE @dataProfilo DATETIME
	DECLARE @varProfilo DECIMAL(5,2)
	DECLARE @nomeProfilo VARCHAR(50)
    DECLARE @riskclass VARCHAR(50)
    DECLARE @experience SMALLINT


	SELECT
        @codiceProfilo = M.PROFILO_ASS,
		@dataProfilo = M.DATA_INIZIO_VAL,
		@varProfilo = CR.MAX_VAR,
		@nomeProfilo = ProfiliDiRischio.NOMEPROFILO,
        @riskclass =  m.riskclass,
        @experience = m.experience
	FROM
		C6MART.MIFID AS M
		INNER JOIN C6MART.CODIFICA_RISCHIO AS CR
		ON M.PROFILO_ASS = CR.PROFILO
		INNER JOIN DBO.ProfiliDiRischio AS ProfiliDiRischio
		ON M.PROFILO_ASS = ProfiliDiRischio.CODICEPROFILO
	WHERE
		M.RETE = @Rete AND
		M.COD_FISCALE = @CodiceFiscale

	SELECT
        @codiceProfilo as codiceProfilo,
		DBO.TOSHORTDATESTRING (@dataProfilo) as dataInizioValidita,
		@varProfilo as varMassimo,
		ISNULL(@varBF,0) as varBF,
		ISNULL(@coperturaBF,0) as coperturaBF,
		@nomeProfilo as nomeProfilo,
        @riskclass as riskclass,
        @experience as experince

END



