99 lines
3.9 KiB
SQL
99 lines
3.9 KiB
SQL
-- Schema: wh
|
|
-- Stored Procedure: MERGED_PROCEDURE_20170615
|
|
|
|
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE procedure [wh].[MERGED_PROCEDURE_20170615]
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
---------------------------------------------------------------------
|
|
|
|
|
|
truncate table wh.pl_s85rendimentoportafogliocono
|
|
truncate table wh.pl_areemonitorate
|
|
truncate table wh.pl_s43lineaselfbf
|
|
truncate table wh.pl_s10patrimoniofinanziario
|
|
truncate table wh.pl_prodotti_non_associati_area_inv
|
|
truncate table wh.pl_d2_s151profilodirischio
|
|
truncate table wh.pl_d2_s152patrimonio
|
|
truncate table wh.pl_d2_s153patrimoniofinanziario
|
|
truncate table wh.pl_d2_s154patrimoniofinanziario
|
|
truncate table wh.pl_d2_s155patrimonioimmobiliare
|
|
truncate table wh.pl_d2_s156altropatrimonio
|
|
truncate table wh.pl_d2_s157confrontopiramidi
|
|
truncate table wh.pl_d2_s158piramidemodello
|
|
truncate table wh.pl_d2_s159patrimoniofinanziario
|
|
truncate table wh.pl_d2_s160dettaglioprodottibf
|
|
truncate table wh.pl_d2_s162dettaglioprodotti
|
|
truncate table wh.pl_d2_s163patrimoniofinanziariomassetclass
|
|
truncate table wh.pl_d2_s164polizzealtriistituti
|
|
truncate table wh.pl_d2_s165fondialtriistituti
|
|
truncate table wh.pl_d2_s167distribuzionerischiocredito
|
|
truncate table wh.pl_d2_s168tabellaemittenti
|
|
truncate table wh.pl_s43dettaglioprodottibf
|
|
truncate table wh.pl_d2_s169rischiomercatorischiocredito
|
|
truncate table wh.pl_d2_s170rischiodiversificazione
|
|
truncate table wh.pl_d2_s171patrimoniononrappresentabileassettclass
|
|
truncate table wh.pl_mp_s137bonus
|
|
truncate table wh.pl_mp_s135monitoraggioinvestimento
|
|
truncate table wh.pl_mp_s134monitoraggioliquidita
|
|
truncate table wh.pl_mp_s134bismonitoraggioliqinv
|
|
truncate table wh.pl_mp_s133bisprincipaliprodotti
|
|
truncate table wh.pl_mp_s133areebisognoprincprod
|
|
truncate table wh.pl_mp_s146rischiodiversificazione
|
|
truncate table wh.pl_mp_s141analisirisparmiotable
|
|
truncate table wh.pl_mp_s140analisirisparmiocharts
|
|
truncate table wh.pl_mp_s137biscapitaleprotetto
|
|
truncate table wh.pl_s43contocorrentebf
|
|
truncate table wh.pl_s43bisdettaglioprodottibf
|
|
truncate table wh.pl_s88patrimoniononconsideratonelcalcolodelrendimento
|
|
truncate table wh.pl_s82datisintetici
|
|
truncate table wh.pl_s82bisdatisintetici
|
|
truncate table wh.pl_s76alternativapatrimoniononrappresentabileassettclass
|
|
truncate table wh.pl_s80alternativa
|
|
truncate table wh.pl_s96rischiomercatorischiocredito
|
|
truncate table wh.pl_d_s170rischiodiversificazione
|
|
------------------------------------------------------------------------
|
|
|
|
-------------------------------------------PL_S82DatiSintetici
|
|
INSERT INTO WH.PL_S82DatiSintetici
|
|
SELECT 'C6MartPeriodico.PL_S82DatiSintetici' as ProcedureName, PATRAREA.RETE as i_rete ,PATRAREA.COD_FISCALE as i_codiceFiscale,
|
|
PATRAREA.ID_AREA AS need_area,
|
|
ISNULL(RISCHIOAREA.VAR_PERC_PTF,0) AS var_needarea,
|
|
CASE
|
|
WHEN RISCHIOAREA.COPERTURA IS NULL THEN 'n.c.'
|
|
WHEN RISCHIOAREA.COPERTURA = 0 THEN 'n.c.'
|
|
ELSE NULL
|
|
END AS var_needareaString,
|
|
|
|
ISNULL(RISCHIOAREA.COPERTURA,0) AS copertura_needarea,
|
|
CASE
|
|
WHEN RISCHIOAREA.COPERTURA IS NULL THEN 'n.c.'
|
|
WHEN RISCHIOAREA.COPERTURA = 0 THEN 'n.c.'
|
|
ELSE NULL
|
|
END AS copertura_needareaString,
|
|
PATRAREA.ORDINAMENTO_PROGETTO,
|
|
/*V Calcolato a livello di codice
|
|
CASE
|
|
WHEN PATRAGGR.CTV = 0 THEN 0
|
|
ELSE PATRAREA.CTV / PATRAGGR.CTV * 100
|
|
END AS pesoPerc,*/
|
|
PATRAREA.CTV AS ControvaloreAttuale
|
|
/* Calcolato a livello di codice
|
|
CASE
|
|
WHEN @TOTRischio = 0 THEN 0
|
|
ELSE ISNULL(RISCHIOAREA.VAR_PERC_PTF,0) * PATRAREA.CTV / @TOTRischio * 100
|
|
END AS rischioRelativo*/
|
|
FROM C6MartPeriodico.vPatrimonioBFAggregatoPerArea AS PATRAREA
|
|
INNER JOIN C6MartPeriodico.vPatrimonioBFAggregato AS PATRAGGR
|
|
ON PATRAGGR.RETE = PATRAREA.Rete
|
|
AND PATRAGGR.COD_FISCALE = PATRAREA.COD_FISCALE
|
|
LEFT OUTER JOIN C6MartPeriodico.RISCHIO_AGGREGATO RISCHIOAREA
|
|
|