PDC_REPORT_CreazioneDB/sql/storedCollaudo/dbo_CREA_CAMPIONE_20160119.sql
2025-06-09 17:09:11 +02:00

215 lines
8.8 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <20141008>
-- Description: <Description,,>
-- =============================================
CREATE procedure [dbo].[CREA_CAMPIONE_20160119]
-- Add the parameters for the stored procedure here
AS
BEGIN
---------------------------------------------------------------
--SELEZIONE DEI PRIMI 200 CLIENTI ORDINATI PER NUMERO DI CASI--
---------------------------------------------------------------
select distinct campione.*
into #appoCamp1
from (
select b.*
FROM [C6MartPeriodico].[selezionecampione2] A
inner join (
SELECT d.*,
([c1]+[c2]+[c3]+[c4]+[c5]+[c6]+[c7]+[c8]+[c9]+[c10]+[c11]+[c12]+[c13]+[c14]+[c15]+[c16]+[c17]+[c18]+[c19]+[c20]
+[c21]+[c22]+[c23]+[c24]+[c25]+[c26]+[c27]+[c28]+[c29]+[c30]+[c31]+[c32]+[c33]+[c34]+[c35]+[c36]+[c37]+[c38]+[c39]+[c40]
+[c41]+[c42]+[c43]+[c44]+[c45]+[c46]+[c47]+[c48]+[c49]+[c50]+[c51]+[c52]+[c53]+[c54]+[c55]+[c56]+[c57]+[c58]
) tot FROM [C6MartPeriodico].[selezionecampione2] d
) B
on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
-- where c2 > 0
) campione
select distinct campione.*
into #appoCamp2
from #appoCamp1 campione
inner join
(
select rete,cod_fiscale
from consevo_periodico.ConsulenzaEvoluta.dbo.MonitoraggioStorico s
inner join c6stagingperiodico.appo_contratti a
on a.chiaveclientepb=s.chiaveclientePB
and datediff(dd,dtAvvio,dtsalvataggio) =0 ) diffdate
on campione.rete=diffdate.rete and campione.cod_fiscale=diffdate.cod_fiscale
select d.rete,d.cod_fiscale,id_area,nome_progetto,max(data_cono) dt
into #appoggio
from C6MartPeriodico.CONO_PIANIFICAZIONE d
where d.cod_fiscale in (
select d.cod_fiscale from #appoCamp2) -- dbo.campionetrimestrale - appocampionereport
group by d.rete,cod_fiscale,id_area,nome_progetto
select a.*
into #appoCamp3
from #appoCamp2 a
left join
(select rete,cod_fiscale,dt
from #appoggio
where dt < '20140930') e
on a.rete=e.rete and a.cod_fiscale=e.cod_fiscale
where e.rete is null
order by tot desc
insert into appocampionereport
select top 175
--DISASTERISCARE PER "INSERT SELECT" ed ASTERISCARE PER "SELECT"
a.rete,a.cod_fiscale,'',b.tip_contratto
--DISASTERISCARE PER "SELECT" ed ASTERISCARE PER "INSERT SELECT"
--case when b.tip_contratto=0 then 'OLD'
-- when b.tip_contratto=1 then 'AFFLUENT'
-- when b.tip_contratto=2 then 'PRIVATE'
--end as TipoContratto,
--a.*
from #appoCamp3 a
inner join C6MARTPERIODICO.CONTRATTOSEI b on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
where a.rete+a.cod_fiscale not in (select rete+cod_fiscale from c6martperiodico.test_quality)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from dbo.disallineati2)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_PROFILO_SCADUTO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_RFA_ZERO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MARTPERIODICO.CONTROLLO_TRIMESTRALE
where stato_report = 23)
order by tot desc
insert into appocampionereport
select top 1
--DISASTERISCARE PER "INSERT SELECT" ed ASTERISCARE PER "SELECT"
a.rete,a.cod_fiscale,'',b.tip_contratto
--DISASTERISCARE PER "SELECT" ed ASTERISCARE PER "INSERT SELECT"
--case when b.tip_contratto=0 then 'OLD'
-- when b.tip_contratto=1 then 'AFFLUENT'
-- when b.tip_contratto=2 then 'PRIVATE'
--end as TipoContratto,
--a.*
from #appoCamp3 a
inner join C6MARTPERIODICO.CONTRATTOSEI b on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
where a.rete+a.cod_fiscale not in (select rete+cod_fiscale from c6martperiodico.test_quality)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from dbo.disallineati2)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_PROFILO_SCADUTO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_RFA_ZERO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MARTPERIODICO.CONTROLLO_TRIMESTRALE
where stato_report = 23)
and c6 > 0
order by b.tip_contratto desc, tot desc
insert into appocampionereport
select top 1
--DISASTERISCARE PER "INSERT SELECT" ed ASTERISCARE PER "SELECT"
a.rete,a.cod_fiscale,'',b.tip_contratto
--DISASTERISCARE PER "SELECT" ed ASTERISCARE PER "INSERT SELECT"
--case when b.tip_contratto=0 then 'OLD'
-- when b.tip_contratto=1 then 'AFFLUENT'
-- when b.tip_contratto=2 then 'PRIVATE'
--end as TipoContratto,
--a.*
from #appoCamp3 a
inner join C6MARTPERIODICO.CONTRATTOSEI b on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
where a.rete+a.cod_fiscale not in (select rete+cod_fiscale from c6martperiodico.test_quality)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from dbo.disallineati2)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_PROFILO_SCADUTO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_RFA_ZERO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MARTPERIODICO.CONTROLLO_TRIMESTRALE
where stato_report = 23)
and c16 > 0
order by b.tip_contratto desc, tot desc
insert into appocampionereport
select top 1
--DISASTERISCARE PER "INSERT SELECT" ed ASTERISCARE PER "SELECT"
a.rete,a.cod_fiscale,'',b.tip_contratto
--DISASTERISCARE PER "SELECT" ed ASTERISCARE PER "INSERT SELECT"
--case when b.tip_contratto=0 then 'OLD'
-- when b.tip_contratto=1 then 'AFFLUENT'
-- when b.tip_contratto=2 then 'PRIVATE'
--end as TipoContratto,
--a.*
from #appoCamp3 a
inner join C6MARTPERIODICO.CONTRATTOSEI b on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
where a.rete+a.cod_fiscale not in (select rete+cod_fiscale from c6martperiodico.test_quality)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from dbo.disallineati2)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_PROFILO_SCADUTO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_RFA_ZERO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MARTPERIODICO.CONTROLLO_TRIMESTRALE
where stato_report = 23)
and c42 > 0
order by b.tip_contratto desc, tot desc
insert into appocampionereport
select
--DISASTERISCARE PER "INSERT SELECT" ed ASTERISCARE PER "SELECT"
a.rete,a.cod_fiscale,'',b.tip_contratto
--DISASTERISCARE PER "SELECT" ed ASTERISCARE PER "INSERT SELECT"
--case when b.tip_contratto=0 then 'OLD'
-- when b.tip_contratto=1 then 'AFFLUENT'
-- when b.tip_contratto=2 then 'PRIVATE'
--end as TipoContratto,
--a.*
from #appoCamp3 a
inner join C6MARTPERIODICO.CONTRATTOSEI b on a.rete=b.rete and a.cod_fiscale=b.cod_fiscale
where a.rete+a.cod_fiscale not in (select rete+cod_fiscale from c6martperiodico.test_quality)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from dbo.disallineati2)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_PROFILO_SCADUTO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MartPeriodico.CONTROLLO_TRIMESTRALE_RFA_ZERO)
and a.rete+a.cod_fiscale not in (select rete+cod_fiscale from C6MARTPERIODICO.CONTROLLO_TRIMESTRALE
where stato_report = 23)
and a.rete+a.cod_fiscale in
('FTGLMRA30A04A409N'
,'FBZZGPP46C18A409M'
,'FCCRGPP54B27H307C'
,'FCRNCST86C56G062N'
,'FGHNDNL46L21G007R'
,'FGNSMNL58D47H037E'
,'FNAIGNE40H10B463Q'
,'FNCLLCU74M70L682S'
,'FPRNNTN32B06E003M'
,'FPRTNMR29R62L219X'
,'FRLDLCN35B18A409N'
,'FRPILNI47M11L746H'
,'FSNEPMR60S24I976R'
,'FTBRFRZ68L20H037P'
,'FTBRGBR37R22G062P'
,'FTBRMRZ65H27H037W'
,'FTTTGDE24D04A409P'
,'FBRLGCR25P13B885H'
,'FMRNNZE22A01F205W'
,'FMRNGMR53P60F205P'
--casi test richiesti da scirocco 10/12/2015 per FOI80
,'FBLNMGR55B56D332B'
,'FDNGGSN33A68B910W'
,'FFVRPLA56S48Z614J'
,'FDLLGNN47C09F952J'
,'FDBNMRA65E67L049H'
,'FLNZMLN35C46A564D'
,'FCLNGNN47P06E606N'
,'FBCHMTN58B07E398F'
,'SSCSCMD53D12F052Q'
--CASI TEST Rossi Rosanna: Segnalazione di errata rendicontazione nel report di monitoraggio SEI - tt T-1205349-F4W8
,'FRSSRNN48C44A783Z'
-- CASI TEST PER CF CHE HANNO PRODOTTI DI BANCHE IN DEFAULT
,'FBNCMHL27S63I760X'
,'FCNTRME55S24B853O'
,'FCRMVGN49S53F791G'
,'FCRSGPT53M02D548K'
,'FGNAGLL33E53A393A'
,'FMGNLRI75A60H901Z'
,'FMGNLRI75A60H901Z'
,'FMNZMNL46C62A393V'
,'FMRNMNG53P46H294F'
,'FNTRMRZ67T17H223L'
,'FPLZLRA40T54L390R'
,'FPRTCHR52L69H017M'
,'FSRVDDE31L44A191J'
, 'SBNOSDR61T03F205W'
,'SBNOSDR61T03F205W'
,'SCLCLNE41M47H434D'
,'SCLCLNE41M47H434D'
,'SCPPBRN41H45C773S'
,'SMGNCRN32R54G547I'
,'SMZZCRL31P55G916D'
,'SSVLSFN64B08A390G'
)
drop table #appoCamp1
drop table #appoCamp2
drop table #appoCamp3
truncate table C6MartPeriodico.TB_Campione
insert into C6MartPeriodico.TB_Campione
select rete, cod_fiscale, 1 --1 è il campo flag stampa che indica che dev esser stampato in fase di generazione del campione, 0 niente stampa
from appocampionereport
END