pears.wtd_start_of_hol_year

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

Original SQL

CREATE FUNCTION "pears"."wtd_start_of_hol_year"( 
  /* Application Maintained Function / Procedure - DO NOT EDIT*/
  IN "pid" CHAR(20),IN "yr" INTEGER,IN "wk" INTEGER ) 
RETURNS DATE
BEGIN
  DECLARE "sdate" DATE;
  DECLARE "wedate" DATE;
  SET "wedate" = "date"("weekenddate"("yr","wk"));
  IF "wedate" IS NULL THEN -- Off the range of known weeks
    RETURN NULL
  END IF;
  SELECT "min"("startdate") INTO "sdate" FROM "pay_employment" WHERE "personid" = "pid"
    AND("enddate" IS NULL OR "enddate" >= "wedate"-13); --(still working or stopped >= last week)
  IF "sdate" IS NULL THEN
    RETURN NULL
  END IF;
  SET "sdate" = "getholidayyear"("sdate","wedate"-7); --Does 1/10/1998 threshold, and rolls forward if > 1 year ago
  RETURN "sdate"
END