PDC_REPORT_CreazioneDB/sql/Testbes/procedure/C6MartPeriodico_Estrazione_Campione.sql
2025-06-10 15:29:00 +02:00

40 lines
4.2 KiB
SQL

CREATE procedure [C6MartPeriodico].[Estrazione_Campione]
AS
BEGIN
drop table if exists C6MartPeriodico.TB_Estrazione_Campione
select top(1) rete_acn,codice_fiscale,'Cliente W Retail (Non Professionale) con solo Monitoraggio' as Nota into C6MartPeriodico.TB_Estrazione_Campione from C6MartPeriodico.tabellone where rete_acn='W' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente W Private (Non Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='W' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente W Retail (Non Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='W' and segmento='PRIVATE' and freq_diagnosi='T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Retail (Non Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Retail (Non Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento<>'PRIVATE' and freq_diagnosi='T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Private (Non Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Retail (Non Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Retail (Non Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento<>'PRIVATE' and freq_diagnosi='T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Private (Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Private (Non Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Retail (Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Retail (Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento<>'PRIVATE' and freq_diagnosi='T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente F Private (Non Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='F' and segmento='PRIVATE' and freq_diagnosi='T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Retail (Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Private (Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente S Private (Non Professionale) con Monitoraggio e Diagnosi'as Nota from C6MartPeriodico.tabellone where rete_acn='S' and segmento='PRIVATE' and freq_diagnosi='T' and flgprof<>'S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente W Retail (Professionale) con solo Monitoraggio' as Nota from C6MartPeriodico.tabellone where rete_acn='W' and segmento<>'PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
union all
select top(1) rete_acn,codice_fiscale,'Cliente W Private (Professionale) con solo Monitoraggio'as Nota from C6MartPeriodico.tabellone where rete_acn='W' and segmento='PRIVATE' and freq_diagnosi<>'T' and flgprof='S'
END