﻿-- =============================================
-- Author:		Berni Francesco
-- Create date: 24 Aprile 2009
-- Description: 
-- =============================================
-- [C6MartPeriodico].[GC_REPORTDACANCELLARESELECT] 
CREATE procedure [C6MartPeriodico].[GC_REPORTDACANCELLARESELECT]
 -- Add the parameters for the stored procedure here
 @flag char(1)
AS
BEGIN
if (@flag = 'A') 
	   -- ANNULLA REPORT
	   Select distinct IdReport from	C6MartPeriodico.GESTIONE_PDF_FTP
	   where  isnull(FlagInvio,'N') = 'N'
else if (@flag = 'C')
	   -- CONVALIDA REPORT
	   Select distinct C6MartPeriodico.GESTIONE_PDF_FTP.IdReport 
	   FROM	C6MartPeriodico.GESTIONE_PDF_FTP
	   INNER JOIN C6MartPeriodico.VERIFICHECAMPIONE
	   ON C6MartPeriodico.GESTIONE_PDF_FTP.IdReport = C6MartPeriodico.VERIFICHECAMPIONE.IdReport
	   where  isnull(C6MartPeriodico.GESTIONE_PDF_FTP.FlagInvio,'N') = 'N'
	   AND  isnull(C6MartPeriodico.GESTIONE_PDF_FTP.Definitivo, 0) = 0	 	
	   AND C6MartPeriodico.VERIFICHECAMPIONE.Esito = 'KO'
	   AND C6MartPeriodico.VERIFICHECAMPIONE.datafine IS NULL
END