-- =============================================
-- Author:		<Davide Moccia>
-- Create date: <Create Date,,>
-- Description:	<Monitoraggio Private - Capitolo1°-Sintesi-3° sezione >
-- =============================================
--[C6martPeriodico].PL_MP_S130PrincipaliPosizioni 'F','GSTGPL59P03B586G'
CREATE procedure [C6MartPeriodico].[PL_MP_S130PrincipaliPosizioni]
-- 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;
select top 3 ANAGPROD.DESCR_PRODOTTO as Prodotto,
CAST ((PATRBF.CTV) AS DECIMAL (12,2)) AS Controvalore,
CAST(((PATRBF.CTV/(select distinct sum(PATRBF.CTV)
from C6MartPeriodico.PATRIMONIO_BF PATRBF
where PATRBF.RETE = @Rete 
  AND PATRBF.COD_FISCALE = @CodiceFiscale
--INIZIO INTRVENTI OMNIA
--AND PATRBF.ID_AREA <> 'Cc'))*100) AS DECIMAL (12,2)) as PesoRelativo
  AND PATRBF.ID_AREA not in ('Cc','self')))*100) AS DECIMAL (12,2)) as PesoRelativo
--FINE INTRVENTI OMNIA
FROM 
C6MartPeriodico.PATRIMONIO_BF PATRBF
INNER JOIN 
C6MartPeriodico.ANAG_PRODOTTI ANAGPROD 
ON 
	ANAGPROD.COD_PRODOTTO = PATRBF.COD_PRODOTTO
WHERE PATRBF.RETE = @Rete
	AND PATRBF.COD_FISCALE = @CodiceFiscale
    AND PATRBF.CTV <>0
--INIZIO INTRVENTI OMNIA
--  AND PATRBF.ID_AREA <> 'Cc'
    AND PATRBF.ID_AREA not in ('Cc','self')
--FINE INTRVENTI OMNIA
ORDER BY 
Controvalore desc
END