CREATE procedure [C6Mart].[aggiornaDataValidazione] as
begin
select 
	DataGenerazione as data,
	SUBSTRING(NomeFile, 1, 11) as codiceContratto, --SUBSTRING(NomeFile, 0, 12)
	case 
		when (id_fk_zip = -1) then 0
		else 1
	end as definitivo,
	getDate() as dataAggiornamento
from 
(
select 
datagenerazione, nomefile,id_fk_zip, 
row_number() over (partition by SUBSTRING(NomeFile, 1, 11) order by datagenerazione desc ) pippo from --SUBSTRING(NomeFile, 0, 12)
c6mart.gestione_pdf_ftp
)l where pippo =1
end