-- Schema: C6MartPeriodico
-- Stored Procedure: SP_statistiche_app_rendicontazione











--select * from dbo.w6trcli where [Freq_ Diagnosi]='S'


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6MartPeriodico].[SP_statistiche_app_rendicontazione]
as
begin
declare 

--NUMERI
@nr_clientiinperimetro int,
@nr_clientiRFA0 int,
@nr_clientiRFAMinus int,
@nr_clientiProfiloScaduto int,
@nr_clientiBlacklist int,
@nr_clientiinviati int,
@nr_clientidainviare int,
@nr_letteraSostitutiva int,
@nr_clientiImmobiliari int,
@nr_clientiInPerimentroSenzaImmobiliare int,
@nr_Blacklistdiversi int,
@nr_soloClientiImmobiliari int,
@nr_diagnosi int,
@nr_clientirendicontati int,
@nr_lotto1 int,
@nr_lotto2 int,
@nr_lotto3 int,
@nr_lotto4 int,
@nr_lotto5 int,
@nr_lotto6 int,
@nr_lotto7 int,
@nr_lotto8 int,
@nr_lotto9 int,
@nr_lotto10 int,
@nr_clientiinviati_IMM int,
@nr_clientidainviare_IMM int,
@nr_clientiBlacklist_IMM int,
@nr_clientirendicontati_IMM int,
@nr_lotto1_IMM int,
@nr_clientiDiagnosiInviati int,
@nr_clientiDiagnosidaInviare int,
@nr_clienticonMonitoraggio int,
@nr_clientiConImmESei int,
@nr_clientiConSoloImm int,
@nr_letteraSostitutivaImm int,
@nr_clientiRFAMinusImm int,
@nr_clientiProfiloEC int




select @nr_clientiInPerimetro=  COUNT(*) from C6MartPeriodico.tabellone where solo_rend_imm='N' or solo_rend_imm is NULL--clienti in perimetro
select @nr_clientiRFA0 =  COUNT(*) from C6MartPeriodico.tabellone where blacklist like '%RFA=0%' --clienti con RFA0
select @nr_clientiRFAMinus =  COUNT(*) from C6MartPeriodico.tabellone where blacklist like '%RFA Minus%' --clienti con RFA0
select @nr_clientiProfiloScaduto=  COUNT(*) from C6MartPeriodico.tabellone where blacklist like '%Profilo Scaduto%' and (blacklist not like '%RFA=0%' and blacklist not like '%RFA Minus%') --clienti con il profilo scaduto
select @nr_clientiBlacklist=  COUNT(*) from C6MartPeriodico.tabellone where blacklist is not null
select @nr_letteraSostitutiva= COUNT(*) from C6MartPeriodico.tabellone where blacklist like '%RFA=0%' or blacklist like '%profilo%' or blacklist like '%RFA Minus%'
--select @nr_clientiBlacklist=  COUNT(*) from C6MartPeriodico.tabellone where blacklist is not null --clienti in blacklist
select @nr_clientiinviati=  COUNT(*) from C6MartPeriodico.tabellone where lotto is not null  --clienti con report gia inviato
set @NR_clientidainviare= @nr_clientiinperimetro-@nr_clientiinviati-@nr_letteraSostitutiva--@nr_clientiBlacklist --clienti con report da inviare
--select @nr_letteraSostitutiva= COUNT(*) from C6MartPeriodico.tabellone where blacklist like '%sostitutiva%'--like '%RFA%' or blacklist like '%profilo%'
select @nr_clientiImmobiliari = COUNT(*) from C6MartPeriodico.tabellone where flgpe_perimetro_semestr='S'
set @nr_clientiInPerimentroSenzaImmobiliare=@nr_clientiinperimetro-@nr_clientiImmobiliari
select @nr_Blacklistdiversi=@nr_clientiBlacklist-@nr_letteraSostitutiva
select @nr_soloClientiImmobiliari= COUNT(*) from C6MartPeriodico.tabellone where solo_rend_imm='S'
select @nr_diagnosi= COUNT(*) from C6MartPeriodico.tabellone where freq_diagnosi <> ''
set @nr_clientirendicontati=@nr_clientiinperimetro-@nr_letteraSostitutiva--@nr_clientiBlacklist
select @nr_lotto1= count(*) from c6martperiodico.tabellone where lotto=1
select @nr_lotto2= count(*) from c6martperiodico.tabellone where lotto=2 
select @nr_lotto3= count(*) from c6martperiodico.tabellone where lotto=3
select @nr_lotto4= count(*) from c6martperiodico.tabellone where lotto=4
select @nr_lotto5= count(*) from c6martperiodico.tabellone where lotto=5
select @nr_lotto6= count(*) from c6martperiodico.tabellone where lotto=6
select @nr_lotto7= count(*) from c6martperiodico.tabellone where lotto=7
select @nr_lotto8= count(*) from c6martperiodico.tabellone where lotto=8
select @nr_lotto9= count(*) from c6martperiodico.tabellone where lotto=9
sel
