====== pears.ComplianceScore ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."ComplianceScore"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in "pPersonID" char(20),in "pVacancyID" char(20) default null ) returns double begin declare "act" double; declare "poss" double; declare "pComplianceDomainID" char(20); declare "pClientCode" char(12); declare "pDate" date; declare "pDeptID" char(2); set "act" = 0; set "poss" = 0; if "pVacancyID" is not null then select "v"."ComplianceDomainID","v"."StartDate","v"."DepartmentID","c"."TempComplianceCode" into "pComplianceDomainID","pDate","pDeptID","pClientCode" from "vacancy" as "v" key join "employment" join "company" as "c" where "v"."vacancyid" = "pVacancyID"; if "pComplianceDomainID" is null then select first "ComplianceDomainID" into "pComplianceDomainID" from "ComplianceDomain" where "DepartmentID" = "pDeptID" and "Name" like 'Default%' and("ClientTempComplianceCode" is null or "ClientTempComplianceCode" = "pClientCode") order by "ClientTempComplianceCode" desc,"Name" asc end if; if "pComplianceDomainID" is null then return 0 end if end if; for "PFOR" as "PCUR" no scroll cursor for select "AchievedScore","Score" from "ComplianceTable"("pPersonID","pComplianceDomainID","pDate","pClientCode") for read only do set "act" = "act"+"isnull"("AchievedScore",0.0); set "poss" = "poss"+"isnull"("Score",0.0) end for; if "poss" <= 0 then return 0 else return("act"/"poss")*100.0 end if end