SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE FUNCTION "public"."exists_deparment_code_interval"("dep_code_id" int4, "dep_id" int4, "typee_id" int4, "from_dt" date, "to_dt" date)
  2.   RETURNS "pg_catalog"."bool" AS $BODY$
  3.                 DECLARE
  4.                     result boolean;
  5.                     rec record;
  6.                 BEGIN
  7.                     FOR rec IN
  8.                     SELECT
  9.                         dc.id, dc.from_dt, dc.to_dt
  10.                         FROM pim_department_code dc
  11.                         WHERE dc.department_id = dep_id and dc.type_id = typee_id and dc.id !=dep_code_id
  12.                     loop
  13.                         select overlaps(coalesce(rec.from_dt, date '01.01.0001'), coalesce(rec.to_dt, date '01.01.3000'), coalesce(from_dt, date '01.01.0001'), coalesce(to_dt, date '01.01.3000'))
  14.                         into result;
  15.                         if (result = 't') then
  16.                             return true;
  17.                         end if;
  18.                     end loop;
  19.                     return false;
  20.                 END;
  21.                 $BODY$
  22.   LANGUAGE plpgsql VOLATILE
  23.   COST 100
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top