CREATE VIEW [dbo].[FLRPT_InvioReport] AS SELECT pdf.IdReport AS KeyReport, pdf.CodiceFiscale AS CodFiscale, pdf.Rete AS CodRete, pdf.Rete + C6.Cod_Agente AS CodAgente, '' AS CodMan, CASE WHEN TipoReport = 'D' THEN 'DIAGNOSI' ELSE 'MONITORAGGIO' END AS TipoReport, pdf.DataInvio AS DtInvio, pdf.DataGenerazione AS DtGenerazione FROM C6Mart.GESTIONE_PDF_FTP AS pdf INNER JOIN C6Mart.CONTRATTOSEI AS C6 ON pdf.Rete = C6.Rete AND pdf.CodiceFiscale = C6.Cod_Fiscale AND pdf.DataGenerazione>C6.data_perf WHERE (C6.Data_FineAvanzato IS NULL)