PDC_REPORT_CreazioneDB/sql/storedProduzione/C6MartPeriodico_Popola_W6ASSETPERC.sql
2025-06-06 19:02:52 +02:00

47 lines
1.7 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE procedure [C6MartPeriodico].[Popola_W6ASSETPERC_newJoin]
AS
BEGIN
SET NOCOUNT ON;
delete from [consuni].consulenzaunica.[dbo].[W6ASSETPERC]
INSERT INTO [consuni].consulenzaunica.[dbo].[W6ASSETPERC]
(
[COD_INTERNO]
,[COD_SOTTOPRODOTTO]
,[COD_ISIN]
,[COD_MAF]
,[ID_ASSETCLASS]
,[CATALOGUENAME]
,[ASSETCLASSNAME]
,[BDPERCENTAGE]
----------modifica del 24/6/2019
,[Visibilita]
----------FINE modifica del 24/6/2019
)
-- modifica richiesta il 25-26/6/2019 (Tesi/Scirocco) - modificata la join tra le tabelle per caricare anche i prodotti che non sono mappati
SELECT DISTINCT
isnull(cat.CodInterno,'') AS COD_INTERNO,
isnull(cat.CodSottoprodotto,'') AS COD_SOTTOPRODOTTO,
isnull(cat.CodIsin,'') AS COD_ISIN,
isnull(cat.CodMaf,'') AS COD_MAF,
isnull(LTRIM(RTRIM(map.Asset)),'') AS ID_ASSETCLASS,
isnull(cat.NomeProdotto,'') as CATALOGUENAME,
isnull(map.Descrizione,'') as ASSETCLASSNAME,
isnull(LTRIM(RTRIM(map.Percentuale)),0) AS BDPERCENTAGE,
--map.Percentuale AS BDPERCENTAGE,
-- ----------modifica del 24/6/2019
--isnull(cat.visibilita,'') AS VISIBILITA
cat.visibilita AS VISIBILITA
----------FINE modifica del 24/6/2019
FROM C6StagingPeriodico.RP_CatalogoProdotti cat
left join (select m.chiaveprodotto,a.Asset,a.Descrizione,m.Percentuale from C6StagingPeriodico.RP_Mappatura m
inner join C6StagingPeriodico.RP_AssetClass a
ON a.Asset = m.Asset and a.Livello = 2
) AS map ON map.ChiaveProdotto = cat.ChiaveProdotto
WHERE 1=1
and cat.CodInterno is not null
END