84 lines
3.9 KiB
Transact-SQL
84 lines
3.9 KiB
Transact-SQL
-- Schema: wh
|
|
-- Stored Procedure: MERGED_PROCEDURE_S178
|
|
|
|
|
|
|
|
|
|
CREATE procedure [wh].[MERGED_PROCEDURE_S178]
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
|
|
DECLARE @DataFineTrim VARCHAR(8)
|
|
SET @DataFineTrim = c6martperiodico.getTrimestre2(getDate(),0)
|
|
|
|
--exec [C6MartPeriodico].[PL_D2_S169RischiomercatoRischiocredito] 'F', '00158650309'
|
|
|
|
--exec [C6MartPeriodico].[PL_D_S178IndicatoriEsitoAdeguatezza] 'F', '00158650309'
|
|
--exec [wh].[p_PL_D_S178IndicatoriEsitoAdeguatezza] 'F', '00158650309'
|
|
|
|
insert into [wh].[PL_D_S178IndicatoriEsitoAdeguatezza]
|
|
select 'C6MartPeriodico.PL_D_S178IndicatoriEsitoAdeguatezza', a.i_rete, a.i_CodiceFiscale,
|
|
|
|
a.i_rete,
|
|
a.i_CodiceFiscale,
|
|
|
|
-- RISCHIO MERCATO
|
|
--var, varmax,
|
|
case
|
|
when var <= varmax then '1'
|
|
when var > varmax then '0'
|
|
else -1
|
|
end as RM_Adeguatezza,
|
|
case
|
|
when var <= varmax then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 1 and Adeguato = '1')
|
|
when var > varmax then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 1 and Adeguato = '0')
|
|
else (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 1 and Adeguato = '-1')
|
|
end as RM_Descrizione,
|
|
-- FINE RISCHIO MERCATO
|
|
|
|
-- RISCHIO CREDITO
|
|
--RISKCLASS, RISKCLASSMAX,
|
|
case
|
|
--20180820 CR su Rischio Credito: quando non è stato possibile calcolare il rischio credito (quindi il valore di RISKCLASS restituito dalla PL_D2_S169RischiomercatoRischiocredito è NULL)
|
|
-- l'indicatore di adeguatezza Rischio Credito è 1 (Adeguato)
|
|
when RISKCLASS is null then '1'
|
|
--20180820 FINE CR su Rischio Credito
|
|
when RISKCLASS <= convert(int,RISKCLASSMAX) then '1'
|
|
when RISKCLASS > convert(int,RISKCLASSMAX) then '0'
|
|
else -1
|
|
end as RC_Adeguatezza,
|
|
case
|
|
--20180820 CR su Rischio Credito: quando non è stato possibile calcolare il rischio credito (quindi il valore di RISKCLASS restituito dalla PL_D2_S169RischiomercatoRischiocredito è NULL)
|
|
-- l'indicatore di adeguatezza Rischio Credito è 1 (Adeguato)
|
|
when RISKCLASS is null then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 2 and Adeguato = '1')
|
|
--20180820 FINE CR su Rischio Credito
|
|
when RISKCLASS <= convert(int,RISKCLASSMAX) then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 2 and Adeguato = '1')
|
|
when RISKCLASS > convert(int,RISKCLASSMAX) then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 2 and Adeguato = '0')
|
|
else (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 2 and Adeguato = '-1')
|
|
end as RC_Descrizione,
|
|
-- FINE RISCHIO CREDITO
|
|
|
|
-- CONCENTRAZIONE EMITTENTI
|
|
--b.concemi,
|
|
case
|
|
when upper(b.concemi) = 'S' then '1'
|
|
when upper(b.concemi) = 'N' then '0'
|
|
else -1
|
|
end as CE_Adeguatezza,
|
|
case
|
|
when upper(b.concemi) = 'S' then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 3 and Adeguato = '1')
|
|
when upper(b.concemi) = 'N' then (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 3 and Adeguato = '0')
|
|
else (select [DescrizioneEsito] from [C6MartPeriodico].[TB_S178IndicatoriEsitoAdeguatezza_Note] where ordine = 3 and Adeguato = '-1')
|
|
|
|
end as CE_Descrizione,
|
|
-- FINE CONCENTRAZIONE EMITTENTI
|
|
|
|
-- COMPLESSITA'
|
|
--b.flgprof, b.flagpg, b.flagnqp, b.flgprlrde, b.clcompl,
|
|
case
|
|
when b.flgprof = 'S' then 'prof'
|
|
when b.flagpg = 1 and b.flgprof = 'N' and b.flagnqp = 'S' and b.flgprlrde = 'N' then '-1' --Massimiliano dice che va messo prima di tutti senza testare altri flag 17/5/2018
|
|
when upper(b.clcompl) = 'N' and
|
|
(select nocompl from [C6
|