127 lines
3.8 KiB
Transact-SQL
127 lines
3.8 KiB
Transact-SQL
-- Schema: C6Mart
|
|
-- Stored Procedure: Popolamento_RP_W6DAILY
|
|
|
|
|
|
|
|
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE PROCEDURE [C6Mart].[Popolamento_RP_W6DAILY]
|
|
|
|
AS
|
|
BEGIN
|
|
|
|
SET NOCOUNT ON;
|
|
|
|
--dichiaro variabile data di trimestrale
|
|
DECLARE @dttrim int
|
|
|
|
--valorizzo la data di trimestrale al giorno del congelamento
|
|
set @dttrim = CAST(CONVERT(varchar, CAST(getdate() as DATETIME),112) as int)
|
|
--print @dttrim
|
|
|
|
--Tronchiamo la tabella RP_vTuttiIPortafogli_Aladdin_tab e la ripopoliamo
|
|
--a partire dalla vista RP_vTuttiIPortafogli_Aladdin
|
|
|
|
Truncate table C6StampeCentralizzate.C6Mart.w6daily
|
|
--
|
|
insert into C6StampeCentralizzate.C6Mart.w6daily
|
|
select
|
|
'G' as FLGCLI ,
|
|
'M' as FLGBL ,
|
|
'A' as TIPOELA,
|
|
@dttrim as DTTRIM,
|
|
rete,
|
|
codfis,
|
|
piva,
|
|
codman,
|
|
'' as CODFID,
|
|
'' as CODAGE,
|
|
CASE
|
|
--WHEN cod_interno <> 'SINT3MEUR' and famprodt = 'DT' THEN isnull(cod_interno,'')
|
|
WHEN ((cod_interno <> 'SINT3MEUR' and cod_interno <> 'SINT6MEUR') and famprodt = 'DT') THEN isnull(cod_interno,'')
|
|
ELSE ''
|
|
END as CODABI,
|
|
ISNULL(termid,00000000),
|
|
cast(annos as int) as anno ,
|
|
cast(progs as int) as prog ,
|
|
0 as quote,
|
|
cast(ctvreale as float) as CTV,
|
|
codconf, --17
|
|
rubr,
|
|
custgar,
|
|
ISNULL(cod_interno,''),
|
|
'' as codana,
|
|
CASE
|
|
WHEN cast(annos as int) <> 0 and cast(progs as int) <> 0 then 'S'
|
|
ELSE 'N'
|
|
END as FLAGPCT,
|
|
--CASE
|
|
-- WHEN famprodt <> 'DT' and famprodt <> 'CC' THEN isnull(cod_interno,'')
|
|
-- ELSE ''
|
|
--END
|
|
'' as codprod,
|
|
ISNULL(cod_sottoprodotto,''),
|
|
ISNULL(cod_isin,''),
|
|
'' as codlinea,
|
|
tipoptf,
|
|
area,
|
|
progetto,
|
|
isnull(codprj,'') as codprj,
|
|
ISNULL(chiave_prodotto_terzi,''),
|
|
ISNULL(assetterzi,''),
|
|
ISNULL(famprodt,''),
|
|
ISNULL(intermediario,''),
|
|
ISNULL(codiceadeguatezza,''),
|
|
ISNULL(cod_maf,''),
|
|
conto,
|
|
numpolizza,
|
|
position_id,
|
|
'' as PREFSOST,
|
|
'' as FLAGAMB,
|
|
'' as FLAGSOC,
|
|
'' as FLAGGOV
|
|
from [C6StampeCentralizzate].[C6Mart].[RP_vTuttiIPortafogli_Aladdin]
|
|
|
|
-- Aggiungiamo le informazioni mancanti per il codman piva_fiduciaria
|
|
update C6StampeCentralizzate.C6Mart.w6daily
|
|
set codprj = ''
|
|
where codprj = 0
|
|
|
|
select substring(b.codicefiscale,4,len(b.codicefiscale)) as codman,b.rete,b.pivafiduciaria into
|
|
#tab
|
|
from C6StampeCentralizzate.C6Mart.w6daily a
|
|
inner join (select distinct rete,codicefiscale,pivafiduciaria from [C6StampeCentralizzate].[C6Staging].[SPB_CONTR_SINTESI] where pivafiduciaria is not null ) b
|
|
on a.rete=b.rete and isnull(a.codman,'')=isnull(substring(b.codicefiscale,4,len(b.codicefiscale)),'')
|
|
|
|
|
|
--select b.cod_mandato,b.rete,b.piva_fiduciaria into
|
|
-- #tab
|
|
-- FROM
|
|
-- [C6StampeCentralizzate].[C6MartPeriodico].[w6clirep] a
|
|
-- inner join (select distinct rete,cod_mandato,piva_fiduciaria from [C6StampeCentralizzate].[C6StagingPeriodico].[APPO_CONTRATTI_V] where cod_mandato<>'') b
|
|
-- on a.rete= b.rete and isnull(a.codman,'')=isnull(b.cod_mandato,'')
|
|
|
|
update C6StampeCentralizzate.C6Mart.w6daily
|
|
set piva = pivafiduciaria
|
|
from #tab tab
|
|
inner join C6StampeCentralizzate.C6Mart.w6daily as a
|
|
on a.rete= tab.rete and isnull(a.codman,'')=isnull(tab.codman,'')
|
|
|
|
--UPDATE [C6StampeCentralizzate].[C6MartPeriodico].[w6clirep]
|
|
-- set piva = piva_fiduciaria
|
|
-- from #tab tab
|
|
-- inner join [C6StampeCentralizzate].[C6MartPeriodico].[w6clirep] as a
|
|
-- on a.rete= tab.rete and isnull(a.codman,'')=isnull(tab.cod_mandato,'')
|
|
|
|
update C6StampeCentralizzate.C6Mart.w6daily
|
|
set codage = isnull(appo.CODAGENTE,'')
|
|
from C6StampeCentralizzate.C6Mart.w6daily w
|
|
left join (select distinct [RETE],[CODAGENTE],[CODICEFISCALE],[PIVAFIDUCIARIA] from [C6StampeCentralizzate].[C6Staging].[SPB_CONTR_SINTESI] ) appo
|
|
on w.rete= appo.rete and isnull(w.codfis,'') = isnull(appo.CODICEFISCALE,'')
|
|
|
|
----1 update per CF
|
|
--u
|