-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- SIU-GUARANI 3 -- Version 3.0.0 -- Function: f_criterio_tiene_hijos() -- Verifica si la persona tiene hijos -- -- Recibe: Id de la Persona. -- Retorna: Integer: 0 - Tiene Hijos / 1 - No tiene hijos -- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -- DROP FUNCTION f_criterio_tiene_hijos(integer); CREATE OR REPLACE FUNCTION f_criterio_tiene_hijos(_persona integer) RETURNS integer AS $BODY$ -- Variables locales DECLARE _Hijos integer; DECLARE _Fecha date; BEGIN _Hijos := 1; -- No tiene hijos _Fecha := NULL; SELECT Max(fecha_relevamiento) INTO _Fecha FROM mdp_datos_censales WHERE persona = _persona; IF _Fecha IS NULL THEN -- No hay dato censal, retorno como que no trabaja RETURN 1; END IF; -- Recupero cantidad de hijos... SELECT mdp_datos_personales.cantidad_hijos INTO _Hijos FROM mdp_datos_censales, mdp_datos_personales WHERE mdp_datos_censales.persona = _persona AND mdp_datos_censales.fecha_relevamiento = _Fecha AND mdp_datos_personales.dato_censal = mdp_datos_censales.dato_censal; IF _Hijos > 0 THEN -- Tiene Hijos RETURN 0; ELSE -- No tiene Hijos RETURN 1; END IF; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; -- ++++++++++++++++++++++++++++++ Fin Function f_criterio_tiene_hijos ++++++++++++++++ -- REVOKE EXECUTE ON FUNCTION f_criterio_tiene_hijos(integer) FROM public; GRANT EXECUTE ON FUNCTION f_criterio_tiene_hijos(integer) TO public;