362 lines
13 KiB
Transact-SQL
362 lines
13 KiB
Transact-SQL
-- =============================================
|
|
-- Author: <DMO>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
--[C6MartPeriodico].[PL_MP_S128ProfiloRischioAdeguatezza] 'F', 'PVRPGS53C25G388A'
|
|
CREATE procedure [C6MartPeriodico].[PL_MP_S128ProfiloRischioAdeguatezza] --'S','FGGMSM57H28G999D'
|
|
-- 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
|
|
/************* BF *****************/
|
|
DECLARE @varPatrBF DECIMAL(12,2)
|
|
DECLARE @riskClassBF VARCHAR(50)
|
|
DECLARE @FLAGPROF varchar(16)
|
|
SET @FLAGPROF= (select distinct FLGPROF from C6MartPeriodico.WSEIAN2 where rete=@rete and CODFIS=@CodiceFiscale)
|
|
DECLARE @SCADUTO_PARZIALE varchar(16)
|
|
SET @SCADUTO_PARZIALE= (select distinct FLGPROF from C6MartPeriodico.wseirpf where rete=@rete and CODFIS=@CodiceFiscale)
|
|
SELECT
|
|
@codiceProfilo = M.PROFILO_ASS,
|
|
@dataProfilo = M.DATA_INIZIO_VAL,
|
|
@varProfilo = CR.MAX_VAR,
|
|
@nomeProfilo = ProfiliDiRischio.NOMEPROFILO,
|
|
@riskclass = m.riskclass,
|
|
@experience = m.experience
|
|
FROM
|
|
C6MartPERIODICO.MIFID AS M
|
|
INNER JOIN C6MartPERIODICO.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
|
|
/* RECUPERO Rischio Mercaro e Rischio Credito BAnca Fideuram */
|
|
declare @contaCC as int
|
|
select @contaCC = count(*)
|
|
from c6martperiodico.patrimonio_Bf
|
|
where tipo_prodotto = 'CC' and cod_fiscale = @codiceFiscale and rete = @rete
|
|
declare @contaPOS as int
|
|
select @contaPOS = count(*)
|
|
from c6martperiodico.patrimonio_Bf
|
|
where cod_fiscale = @codiceFiscale and rete = @rete
|
|
SELECT
|
|
@varPatrBF = CASE WHEN (@contaPOS - @contaCC) = 0 THEN 0.00
|
|
ELSE RISK_AGG.VAR_PERC_PTF
|
|
END,
|
|
@riskClassBF = RISK_AGG.CREDITRISK
|
|
FROM
|
|
(
|
|
select
|
|
PATRBF.RETE,
|
|
PATRBF.COD_FISCALE,
|
|
CASE WHEN PATRBF.RETE='F' THEN 'Patrimonio Fideuram' WHEN PATRBF.RETE='S' THEN 'Patrimonio Sanpaolo Invest' ELSE ' Patrimonio IW Private Inv.' END AS INSTITUTENAME,
|
|
SUM(PATRBF.CTV) AS CTV
|
|
from
|
|
c6martperiodico.patrimonio_bf PATRBF
|
|
where
|
|
1=1
|
|
and cod_fiscale = @codiceFiscale
|
|
and rete= @rete
|
|
GROUP BY
|
|
PATRBF.RETE,
|
|
PATRBF.COD_FISCALE,
|
|
CASE WHEN PATRBF.RETE='F' THEN 'Patrimonio Fideuram' WHEN PATRBF.RETE='S' THEN 'Patrimonio Sanpaolo Invest' ELSE 'Patrimonio IW Private Inv.' END
|
|
) PATRBF
|
|
LEFT OUTER JOIN
|
|
c6martperiodico.MIFID AS M
|
|
ON
|
|
PATRBF.COD_FISCALE=M.COD_FISCALE
|
|
AND PATRBF.RETE=M.RETE
|
|
LEFT OUTER JOIN c6martperiodico.CODIFICA_RISCHIO AS CR
|
|
ON M.PROFILO_ASS = CR.PROFILO
|
|
LEFT OUTER JOIN
|
|
c6martperiodico.CODIFICA_CREDITRISK CK
|
|
ON
|
|
M.riskclass=CK.PROFILO
|
|
LEFT OUTER JOIN
|
|
c6martperiodico.RISCHIO_AGGREGATO RISK_AGG
|
|
ON
|
|
PATRBF.COD_FISCALE=RISK_AGG.COD_FISCALE
|
|
AND PATRBF.RETE=RISK_AGG.RETE
|
|
left outer join C6MartPeriodico.COMPLESSITA cmp
|
|
on
|
|
CMP.COD_FISCALE=PATRBF.COD_FISCALE
|
|
AND
|
|
CMP.RETE=PATRBF.RETE
|
|
where
|
|
(
|
|
RISK_AGG.COD_AGGREG= 'COMPLESSIVO|BF'
|
|
)
|
|
------------------------ MIFID2 - MAGGIO 2018
|
|
select @coperturaBF=copertura
|
|
from C6MartPeriodico.RISCHIO_AGGREGATO
|
|
-- modifica del 17/10/2018 - Va' preso il compleesivoBF come avviene nella d2_s170_RischioDiversificazione
|
|
--where cod_aggreg='complessivo'
|
|
where cod_aggreg='COMPLESSIVO|BF'
|
|
-- fine modifica del 17/10/2018
|
|
AND COD_FISCALE = @COdiceFISCALE
|
|
and RETE= @RETE
|
|
declare @limiteProfilo as int
|
|
-- modifica del 2/7/2018 -
|
|
--select @limiteProfilo = experience from C6MartPERIODICO.MIFID
|
|
select @limiteProfilo = experience from C6MartPERIODICO.MIFID where cod_fiscale = @CodiceFiscale
|
|
and rete= @Rete
|
|
-- fine modifica del 2/7/2018 -
|
|
declare @maxComplessita as int
|
|
DECLARE @DataFineTrim VARCHAR(8)
|
|
SET @DataFineTrim =c6martperiodico.getTrimestre(getDate(),0)
|
|
if @CodiceFiscale like '%FF@%'
|
|
select @maxComplessita = maxcompl from [C6StagingPeriodico].[WSEIAN2]
|
|
where
|
|
codman = substring(@CodiceFiscale, 4,len(@CodiceFiscale)-3)
|
|
and rete= @Rete
|
|
and DTTRIM = @DataFineTrim
|
|
-- 20180703 bisogna escludere l'eventuale compl_base = 10, che non verrebbe decodificata
|
|
-- and compl_base <> 10; commentata per MUA
|
|
else
|
|
select @maxComplessita = maxcompl from [C6StagingPeriodico].[WSEIAN2]
|
|
where
|
|
codfis= @CodiceFiscale
|
|
and rete= @Rete
|
|
and DTTRIM = @DataFineTrim
|
|
-- 20180703 bisogna escludere l'eventuale compl_base = 10, che non verrebbe decodificata
|
|
-- and compl_base <> 10; commentata per MUA
|
|
------------------------- FINE MIFID2 - MAGGIO 2018
|
|
-- 2/7/2018 - CR NAPOLITANO CASI 11-14 -> Persona Giuridica Retail con Nuovo questionario di profilatura (Legali Rappresentanti/Delegati NON Profilati)
|
|
DECLARE @newLimiteProfilo varchar(20)
|
|
if ltrim(rtrim([C6MartPeriodico].[getIndicatoreValutazione] (@Rete,@CodiceFiscale,default))) = '-1'
|
|
set @newLimiteProfilo = 'n.d.'
|
|
else
|
|
select @newLimiteProfilo =
|
|
(
|
|
case @limiteProfilo
|
|
when 0 then 'Minima'
|
|
when 1 then 'Bassa'
|
|
when 2 then 'Medio bassa'
|
|
when 3 then 'Medio alta'
|
|
when 4 then 'Alta'
|
|
--when 5 then 'Alta'
|
|
else '-'
|
|
end
|
|
)
|
|
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,
|
|
@varPatrBF as varPatrimonioBF,
|
|
@riskClassBF as riskClassBF,
|
|
------------------------ MIFID2 - MAGGIO 2018
|
|
case when @SCADUTO_PARZIALE='P' then '-'
|
|
when @FLAGPROF='S' then 'n.a.'
|
|
else @newLimiteProfilo end as LimiteComplessitaProfilo,
|
|
case @maxComplessita
|
|
when 0 then 'Minima'
|
|
when 1 then 'Bassa'
|
|
when 2 then 'Medio bassa'
|
|
when 3 then 'Medio alta'
|
|
when 4 then 'Alta'
|
|
--when 5 then 'Alta'
|
|
end as LimiteComplessitaPatrimonio
|
|
------------------------- FINE MIFID2 - MAGGIO 2018
|
|
END
|
|
--USE [C6StampeCentralizzate]
|
|
--GO
|
|
--/****** Object: StoredProcedure [C6MartPeriodico].[PL_MP_S128ProfiloRischioAdeguatezza] Script Date: 09/02/2022 11:59:17 ******/
|
|
--SET ANSI_NULLS ON
|
|
--GO
|
|
--SET QUOTED_IDENTIFIER ON
|
|
--GO
|
|
---- =============================================
|
|
---- Author: <DMO>
|
|
---- Create date: <Create Date,,>
|
|
---- Description: <Description,,>
|
|
---- =============================================
|
|
----[C6MartPeriodico].[PL_MP_S128ProfiloRischioAdeguatezza] 's', 'GRTDNL49D01I531Z'
|
|
--ALTER procedure [C6MartPeriodico].[PL_MP_S128ProfiloRischioAdeguatezza]
|
|
-- -- 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
|
|
--/************* BF *****************/
|
|
-- DECLARE @varPatrBF DECIMAL(12,2)
|
|
-- DECLARE @riskClassBF VARCHAR(50)
|
|
-- SELECT
|
|
-- @codiceProfilo = M.PROFILO_ASS,
|
|
-- @dataProfilo = M.DATA_INIZIO_VAL,
|
|
-- @varProfilo = CR.MAX_VAR,
|
|
-- @nomeProfilo = ProfiliDiRischio.NOMEPROFILO,
|
|
-- @riskclass = m.riskclass,
|
|
-- @experience = m.experience
|
|
-- FROM
|
|
-- C6MartPERIODICO.MIFID AS M
|
|
-- INNER JOIN C6MartPERIODICO.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
|
|
--/* RECUPERO Rischio Mercaro e Rischio Credito BAnca Fideuram */
|
|
-- declare @contaCC as int
|
|
-- select @contaCC = count(*)
|
|
-- from c6martperiodico.patrimonio_Bf
|
|
-- where tipo_prodotto = 'CC' and cod_fiscale = @codiceFiscale and rete = @rete
|
|
-- declare @contaPOS as int
|
|
-- select @contaPOS = count(*)
|
|
-- from c6martperiodico.patrimonio_Bf
|
|
-- where cod_fiscale = @codiceFiscale and rete = @rete
|
|
-- SELECT
|
|
-- @varPatrBF = CASE WHEN (@contaPOS - @contaCC) = 0 THEN 0.00
|
|
-- ELSE RISK_AGG.VAR_PERC_PTF
|
|
-- END,
|
|
-- @riskClassBF = RISK_AGG.CREDITRISK
|
|
-- FROM
|
|
-- (
|
|
-- select
|
|
-- PATRBF.RETE,
|
|
-- PATRBF.COD_FISCALE,
|
|
-- CASE WHEN PATRBF.RETE='F' THEN 'Patrimonio Fideuram' ELSE 'Patrimonio Sanpaolo Invest' END AS INSTITUTENAME,
|
|
-- SUM(PATRBF.CTV) AS CTV
|
|
-- from
|
|
-- c6martperiodico.patrimonio_bf PATRBF
|
|
-- where
|
|
-- 1=1
|
|
-- and cod_fiscale = @codiceFiscale
|
|
-- and rete= @rete
|
|
-- GROUP BY
|
|
-- PATRBF.RETE,
|
|
-- PATRBF.COD_FISCALE,
|
|
-- CASE WHEN PATRBF.RETE='F' THEN 'Patrimonio Fideuram' ELSE 'Patrimonio Sanpaolo Invest' END
|
|
-- ) PATRBF
|
|
-- LEFT OUTER JOIN
|
|
-- c6martperiodico.MIFID AS M
|
|
-- ON
|
|
-- PATRBF.COD_FISCALE=M.COD_FISCALE
|
|
-- AND PATRBF.RETE=M.RETE
|
|
-- LEFT OUTER JOIN c6martperiodico.CODIFICA_RISCHIO AS CR
|
|
-- ON M.PROFILO_ASS = CR.PROFILO
|
|
-- LEFT OUTER JOIN
|
|
-- c6martperiodico.CODIFICA_CREDITRISK CK
|
|
-- ON
|
|
-- M.riskclass=CK.PROFILO
|
|
-- LEFT OUTER JOIN
|
|
-- c6martperiodico.RISCHIO_AGGREGATO RISK_AGG
|
|
-- ON
|
|
-- PATRBF.COD_FISCALE=RISK_AGG.COD_FISCALE
|
|
-- AND PATRBF.RETE=RISK_AGG.RETE
|
|
-- left outer join C6MartPeriodico.COMPLESSITA cmp
|
|
-- on
|
|
-- CMP.COD_FISCALE=PATRBF.COD_FISCALE
|
|
-- AND
|
|
-- CMP.RETE=PATRBF.RETE
|
|
-- where
|
|
-- (
|
|
-- RISK_AGG.COD_AGGREG= 'COMPLESSIVO|BF'
|
|
-- )
|
|
-------------------------- MIFID2 - MAGGIO 2018
|
|
-- select @coperturaBF=copertura
|
|
-- from C6MartPeriodico.RISCHIO_AGGREGATO
|
|
-- -- modifica del 17/10/2018 - Va' preso il compleesivoBF come avviene nella d2_s170_RischioDiversificazione
|
|
-- --where cod_aggreg='complessivo'
|
|
-- where cod_aggreg='COMPLESSIVO|BF'
|
|
-- -- fine modifica del 17/10/2018
|
|
-- AND COD_FISCALE = @COdiceFISCALE
|
|
-- and RETE= @RETE
|
|
-- declare @limiteProfilo as int
|
|
-- -- modifica del 2/7/2018 -
|
|
-- --select @limiteProfilo = experience from C6MartPERIODICO.MIFID
|
|
-- select @limiteProfilo = experience from C6MartPERIODICO.MIFID where cod_fiscale = @CodiceFiscale
|
|
-- and rete= @Rete
|
|
-- -- fine modifica del 2/7/2018 -
|
|
-- declare @maxComplessita as int
|
|
-- DECLARE @DataFineTrim VARCHAR(8)
|
|
-- SET @DataFineTrim =c6martperiodico.getTrimestre2(getDate(),0)
|
|
-- if @CodiceFiscale like '%FF@%'
|
|
-- select @maxComplessita = max(compl_base) from [C6StagingPeriodico].[WSEIAD2]
|
|
-- where
|
|
-- codman = substring(@CodiceFiscale, 4,len(@CodiceFiscale)-3)
|
|
-- and rete= @Rete
|
|
-- and DTTRIM = @DataFineTrim
|
|
-- -- 20180703 bisogna escludere l'eventuale compl_base = 10, che non verrebbe decodificata
|
|
-- and compl_base <> 10;
|
|
-- else
|
|
-- select @maxComplessita = max(compl_base) from [C6StagingPeriodico].[WSEIAD2]
|
|
-- where
|
|
-- codfis= @CodiceFiscale
|
|
-- and rete= @Rete
|
|
-- and DTTRIM = @DataFineTrim
|
|
-- -- 20180703 bisogna escludere l'eventuale compl_base = 10, che non verrebbe decodificata
|
|
-- and compl_base <> 10;
|
|
--------------------------- FINE MIFID2 - MAGGIO 2018
|
|
---- 2/7/2018 - CR NAPOLITANO CASI 11-14 -> Persona Giuridica Retail con Nuovo questionario di profilatura (Legali Rappresentanti/Delegati NON Profilati)
|
|
--DECLARE @newLimiteProfilo varchar(20)
|
|
--if ltrim(rtrim([C6MartPeriodico].[getIndicatoreValutazione] (@Rete,@CodiceFiscale,default))) = '-1'
|
|
-- set @newLimiteProfilo = 'n.d.'
|
|
--else
|
|
-- select @newLimiteProfilo =
|
|
-- (
|
|
-- case @limiteProfilo
|
|
-- when 0 then '-'
|
|
-- when 1 then 'Minima'
|
|
-- when 2 then 'Bassa'
|
|
-- when 3 then 'Media'
|
|
-- when 4 then 'Alta'
|
|
-- when 5 then 'Molto alta'
|
|
-- else '-'
|
|
-- end
|
|
-- )
|
|
-- 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,
|
|
-- @varPatrBF as varPatrimonioBF,
|
|
-- @riskClassBF as riskClassBF,
|
|
-------------------------- MIFID2 - MAGGIO 2018
|
|
-- @newLimiteProfilo as LimiteComplessitaProfilo,
|
|
-- case @maxComplessita
|
|
-- when 0 then '-'
|
|
-- when 1 then 'Minima'
|
|
-- when 2 then 'Bassa'
|
|
-- when 3 then 'Media'
|
|
-- when 4 then 'Alta'
|
|
-- when 5 then 'Molto alta'
|
|
-- else '-'
|
|
-- end as LimiteComplessitaPatrimonio
|
|
--------------------------- FINE MIFID2 - MAGGIO 2018
|
|
--END |