====== 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