====== pears.TempGetWeekAgo ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."TempGetWeekAgo"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "StartYear" integer,in "StartWeek" integer,in "WeeksAgo" smallint ) returns integer /* Function returns year and week in format: yyyyww */ begin declare "MaxWeek" smallint; if "WeeksAgo" > 52 then return null end if; if "WeeksAgo" < "StartWeek" then return("StartYear"*100+("StartWeek"-"WeeksAgo")) end if; select "numberofweeks" into "MaxWeek" from "payrollyear" where "yearnumber" = "StartYear"-1; if "maxweek" is null then set "maxweek" = 52 end if; return("StartYear"-1)*100+("MaxWeek"-("WeeksAgo"-"StartWeek")) end