====== pears.GetPersonAvailPercentage ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."GetPersonAvailPercentage"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "sid" char(20),in "frdate" date,in "todate" date ) returns double begin declare "rv" double; declare "bonly" smallint; declare "cavail" char(1); declare "ndays" double; declare "navail" double; set "rv" = 0; if "frdate" is null then return null end if; if "todate" is null then set "todate" = "dateadd"("day",30,"frdate") end if; if "frdate" > "todate" then return 100 end if; set "ndays" = 0; set "navail" = 0; select first "onlymatchifknownavailable" into "bonly" from "person" where "personid" = "sid"; set "bonly" = "isnull"("bonly",0); while "frdate" <= "todate" loop set "ndays" = "ndays"+1; select first "getpersonavailstate"("sid","frdate") into "cavail"; if "cavail" = 'A' or("cavail" is null and "bonly" = 0) then set "navail" = "navail"+1 end if; set "frdate" = "dateadd"("day",1,"frdate") end loop; return("navail"/"ndays")*100 end