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

36 lines
1.2 KiB
Transact-SQL

--[C6MartPeriodico].[SP_TotaliReportGenerazioneZip] 960,1
CREATE PROCEDURE [C6MartPeriodico].[SP_TotaliReportGenerazioneZip]
@reportPerZip int, @isLotto1 int = 0
AS
BEGIN
IF @isLotto1 = 1 and 0 < (select count(*) from [C6MartPeriodico].WHITELIST_ZIP WHERE Pacchetto_Zip is null)
BEGIN
select count(*) totReportGenerati,
2 as isUltimoZip
from [C6MartPeriodico].WHITELIST_ZIP WHERE Pacchetto_Zip is null
END
ELSE
BEGIN
Declare @totReportDaGenerareCT int
Declare @totReportGenerati int
declare @totReportDaNonGenerareCCS int
if @reportPerZip = 0
set @reportPerZip = 960
select @totReportGenerati =COUNT(*)
from C6MartPeriodico.controllo_trimestrale
where stato_report in (4) --1
select @totReportDaGenerareCT =COUNT(*)
from C6MartPeriodico.controllo_trimestrale
where stato_report in (1) --1
select @totReportDaNonGenerareCCS=COUNT(*)
from C6MartPeriodico.CRUSCOTTO_CONTRATTISEI
where elab in(4)
--select @totReportGenerati,@totReportDaGenerareCT,@totReportDaNonGenerareCCS
select @totReportGenerati totReportGenerati,
case when(@totReportDaGenerareCT - @totReportDaNonGenerareCCS) = 0 then
1
else
0
End as isUltimoZip
END
End