CREATE FUNCTION [C6Mart].[getDataPerfUpdate]
(
	@rete varchar(1),
	@cod_fiscale varchar(20)
)
RETURNS datetime
AS
BEGIN
	declare @dtPerf datetime
	select top 1 @dtPerf = TRCOM_DTPERF
	from  [CONSUNI].ConsulenzaUnicaFL.[dbo].CBS_HistDatiIngresso
	where
		trcom_rete = @rete
		and
		trcom_codfisc = @cod_fiscale
		and
		trcom_causale = 'UD6'
	order by data_inserimento_riga desc	
	return @dtPerf
END