CREATE procedure [C6MartPeriodico].[GESTIONE_SELECT_FTP_INVIATI_INCLUDINGFILENAME_20180308_PreIDX2]  
@idFkzip int
AS
BEGIN
       SET NOCOUNT ON;
    SELECT DISTINCT 
            		[C6MartPeriodico].CONCATENA(C6MartPeriodico.GESTIONE_PDF_FTP.Rete, 
		   [C6MartPeriodico].GESTIONE_PDF_FTP.CodiceFiscale) AS riga , (case when tiporeport = 'D' then '' else NomeFile end) as NomeFile
    	FROM [C6MartPeriodico].GESTIONE_PDF_FTP
	INNER JOIN C6MARTPERIODICO.CONTRATTOSEI
		ON CONTRATTOSEI.Rete = GESTIONE_PDF_FTP.Rete
		AND CONTRATTOSEI.COD_FISCALE = GESTIONE_PDF_FTP.CodiceFiscale
	INNER JOIN [C6MartPeriodico].ANAG_CLIENTI 
		ON ANAG_CLIENTI.Rete = GESTIONE_PDF_FTP.Rete
		AND ANAG_CLIENTI.COD_FISCALE = GESTIONE_PDF_FTP.CodiceFiscale
	WHERE 
	 GESTIONE_PDF_FTP.id_fk_zip = @idFkzip 
END