99 lines
2.7 KiB
Transact-SQL
99 lines
2.7 KiB
Transact-SQL
-- Schema: C6MartPeriodico
|
|
-- Stored Procedure: PL_D2_FD152Patrimonio
|
|
|
|
|
|
|
|
|
|
|
|
-- Stored procedure
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
-- [C6MartPeriodico].[PL_D2_S152Patrimonio] 'f','BNLSRG42S13E666Q'
|
|
CREATE procedure [C6MartPeriodico].[PL_D2_FD152Patrimonio]
|
|
|
|
@Rete char(1),
|
|
@CodiceFiscale varchar(16)
|
|
|
|
AS
|
|
|
|
BEGIN
|
|
|
|
DECLARE @PatrimonioBF DECIMAL(15,2)
|
|
DECLARE @Part_viaggianti decimal(15,2)
|
|
DECLARE @PatrimonioRibilanciato DECIMAL(15,2) -- Portafoglio Ribilanciato
|
|
DECLARE @PatrimonioBase DECIMAL(15,2) --Portafoglio Base
|
|
|
|
|
|
|
|
SELECT @PatrimonioBF = SUM(CTV)
|
|
FROM C6MartPeriodico.PATRIMONIO_BF patrBF
|
|
WHERE
|
|
patrBF.Rete = @Rete
|
|
AND patrBF.Cod_Fiscale = @CodiceFiscale
|
|
AND patrBF.id_area not in ('CC','SELF')
|
|
|
|
SELECT @Part_viaggianti = SUM(IMPORTO)
|
|
FROM
|
|
(
|
|
SELECT SUM(IMPORTO) AS IMPORTO
|
|
FROM C6Martperiodico.PARTITE_VIAGGIANTI partvia
|
|
WHERE
|
|
partvia.Rete = @Rete
|
|
and partvia.Cod_Fiscale = @CodiceFiscale
|
|
union
|
|
SELECT SUM(PARTVIA_DISINV) AS IMPORTO
|
|
FROM C6Martperiodico.patrimonio_bf partvia
|
|
WHERE
|
|
partvia.Rete = @Rete
|
|
and partvia.Cod_Fiscale = @CodiceFiscale
|
|
) T
|
|
|
|
select POSITION_ID
|
|
FROM C6MartPeriodico.PATRIMONIO_BF patrBF inner join
|
|
C6StagingPeriodico.RP_Progetto_Robo robo on patrBF.CHIAVE_PROGETTO=robo.chiaveProgetto
|
|
WHERE
|
|
patrBF.Rete = @Rete
|
|
AND patrBF.Cod_Fiscale = @CodiceFiscale
|
|
|
|
select @PatrimonioBase= sum(CTV)
|
|
from C6MartPeriodico.PATRIMONIO_BF patrBF
|
|
WHERE
|
|
patrBF.Rete = @Rete
|
|
AND patrBF.Cod_Fiscale = @CodiceFiscale
|
|
AND patrBF.position_id not in (
|
|
select POSITION_ID
|
|
FROM C6MartPeriodico.PATRIMONIO_BF patrBF inner join
|
|
C6StagingPeriodico.RP_Progetto_Robo robo on patrBF.CHIAVE_PROGETTO=robo.chiaveProgetto
|
|
WHERE
|
|
patrBF.Rete = @Rete
|
|
AND patrBF.Cod_Fiscale = @CodiceFiscale)
|
|
|
|
declare @summa as decimal(15,2)
|
|
SET @Part_viaggianti=coalesce(@Part_viaggianti,0)
|
|
SET @PatrimonioBF =coalesce(@PatrimonioBF,0)
|
|
SET @summa = @PatrimonioBF + @Part_viaggianti
|
|
SET @PatrimonioBF=@summa
|
|
SET @PatrimonioRibilanciato =coalesce(@PatrimonioRibilanciato,0)
|
|
SET @PatrimonioBase =coalesce(@PatrimonioBase,0)
|
|
|
|
SELECT
|
|
@PatrimonioBF AS PatrimonioTotaleCTV,
|
|
@PatrimonioRibilanciato AS PatrimonioRibilanciatoCTV,
|
|
CONVERT(decimal(6,2),((case @PatrimonioRibilanciato when 0.00 then 0.00 else (@PatrimonioRibilanciato)/ @PatrimonioBF end) * 100.00)) AS RibilanciatoPerc,
|
|
@PatrimonioBase AS PatrimonioBaseCTV,
|
|
CONVERT(decimal(6,2),((case @PatrimonioBase when 0.00 then 0.00 else @PatrimonioBase/@PatrimonioBF end ) *100.00)) AS BasePerc
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|