====== pears.GetTempRateByFlag ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."GetTempRateByFlag"( in "PayOrCharge" char(1),in "PlacOrVac" char(1),in "ID" char(20),in "flag" char(20) ) returns double begin declare "pay" double; declare "chg" double; declare "disc" double; declare "bandid" char(20); declare "vid" char(20); set "vid" = "id"; set "pay" = null; set "disc" = 0; select first "temppaybandid" into "bandid" from "temppayband" where "temppayband"."payrollflag" = "flag" order by "sortorder" asc; if "placorvac" = 'P' then select first "payrate","chargerate" into "pay","chg" from "tempjobrate" where "placementid" = "ID" and "temppaybandid" = "bandid" and("startdate" <= current date or "startdate" is null) and("enddate" >= current date or "enddate" is null); if "pay" is null then select first "payrate","chargerate" into "pay","chg" from "tempjobrate" where "placementid" = "ID" and "temppaybandid" = "bandid" end if; if "pay" is null then select "vacancyid" into "vid" from "placement" where "placementid" = "id" end if end if; if "pay" is null then select "isnull"("discount",0) into "disc" from "vacancy" where "vacancyid" = "vid"; select first "payrate","chargerate" into "pay","chg" from "tempjobrate" where "vacancyid" = "vid" and "temppaybandid" = "bandid" and("startdate" <= current date or "startdate" is null) and("enddate" >= current date or "enddate" is null) end if; if "pay" is null then select first "payrate","chargerate" into "pay","chg" from "tempjobrate" where "vacancyid" = "vid" and "temppaybandid" = "bandid" end if; if "payorcharge" = 'P' then return("pay") else return("round"("chg"-("chg"*"disc"/100),2)) end if end