30 lines
1.4 KiB
SQL
30 lines
1.4 KiB
SQL
CREATE VIEW [C6Mart].[vPatrimoniobfAggregato_SenzaNobPrez]
|
|
AS
|
|
SELECT
|
|
PATRIMONIO_bf.RETE,
|
|
PATRIMONIO_bf.COD_FISCALE,
|
|
SUM(case when Upper(id_area)='CC' and ctv<0 then 0 else ctv end) as CTV, --modificata il 04012020 la fonte del ctv con la case when per escludere i cc negativi dal conto
|
|
SUM(case Upper(id_area) when 'NA' then ctv else 0 end ) as PatrimonioNonAssociato,
|
|
SUM(case Upper(id_area) when 'CC' then ctv else 0 end ) as ContoCorrente,
|
|
SUM(case Upper(id_area) when 'CC' then 0 else ctv end ) as PatrimonioSenzaCC,
|
|
--MAX((isnull(PART_VIAGG.PARTVIA_INV,0))) as PartiteViaggiantiInv
|
|
--decommentare ed aggiungere una virgola alla riga sovrastante, indi commentare detta riga
|
|
MAX((isnull(PART_VIAGG.PARTVIA_DISINV,0))) as PartiteViaggiantiDisinv
|
|
FROM C6Mart.PATRIMONIO_bf
|
|
LEFT JOIN
|
|
(
|
|
--commentare Sum Partvia_Inv, decommentare Sum Partvia_Disinv
|
|
SELECT a.rete, a.cod_fiscale, /*sum (a.PARTVIA_INV) AS PARTVIA_INV,*/ sum (a.PARTVIA_DISINV) AS PARTVIA_DISINV
|
|
FROM (
|
|
SELECT DISTINCT rete, cod_fiscale, id_contratto, partvia_disinv --partvia_inv
|
|
FROM C6Mart.PATRIMONIO_bf
|
|
--WHERE partvia_inv IS NOT NULL --commentare questa riga
|
|
) a
|
|
GROUP BY rete, cod_fiscale
|
|
) PART_VIAGG
|
|
ON
|
|
PART_VIAGG.RETE = PATRIMONIO_bf.RETE
|
|
AND PART_VIAGG.COD_FISCALE = PATRIMONIO_bf.COD_FISCALE
|
|
where isnull(PATRIMONIO_bf.Nob_Prez,'N')<>'S'
|
|
GROUP BY
|
|
PATRIMONIO_bf.rete, PATRIMONIO_bf.COD_FISCALE |