Advertisement
jzgeorge

funcion actualizar

Nov 5th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION esq_ceac_planclase.f_departamento_docente(p_idperiodo integer, p_idpersonal bigint)
  2.   RETURNS integer AS
  3. $BODY$
  4. DECLARE
  5.  v_iddepartamento_docente integer;
  6.  v_periodo_fecha_final date;
  7.  v_periodo_fecha_inicial date;
  8. BEGIN
  9.  
  10.     select p.fecha_inicio, p.fecha_final into v_periodo_fecha_inicial, v_periodo_fecha_final from esq_periodos_academicos.periodo_academico p where p.idperiodo = p_idperiodo;
  11.     select d.iddepartamento into v_iddepartamento_docente
  12.                 FROM esq_distributivos.dedicacion_categoria_personal_academico d
  13.                 where d.iddepartamento > 0 and coalesce(coalesce(d.id_rol, 5), 5) in (51, 5,61) and d.idpersonal = p_idpersonal
  14.                     and (d.fecha between v_periodo_fecha_inicial and v_periodo_fecha_final
  15.                           or coalesce(d.fecha_final, '2999/12/31') between v_periodo_fecha_inicial and v_periodo_fecha_final
  16.                           or v_periodo_fecha_inicial BETWEEN d.fecha and coalesce(d.fecha_final, '2999/12/31')
  17.                           or v_periodo_fecha_final BETWEEN d.fecha and coalesce(d.fecha_final, '2999/12/31'))
  18.                           order by d.fecha desc;
  19.                           return v_iddepartamento_docente;
  20. END;
  21. $BODY$
  22.   LANGUAGE plpgsql VOLATILE
  23.   COST 100;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement