IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[f_flo_avanceXActividad]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[f_flo_avanceXActividad]
GO
create function f_flo_avanceXActividad 
(@p_id_actividad as int)
returns float
as begin

return (
select top 1 porcentaje_avance  from pro_reporteactividad 
where id_actividad =@p_id_actividad 
order by fecha_inicio desc)
end

--select dbo.f_flo_avanceXActividad ();

