====== pears.VacancyExtraHols ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."VacancyExtraHols"( in @TempTimeSheetID char(20) )
returns double
begin
declare "rv" double;
-- check earns hol pay
if exists(select * from "temptimesheetline" key join "temppayband" where "temptimesheetid" = @temptimesheetid and "includeinholidaypay" = 1) then
select "vacancy"."ExtraHols" into "rv" from "temptimesheet" key join "placement" key join "vacancy" where "temptimesheetid" = @TempTimeSheetID
end if;
-- deal with contras
if(select "sum"("unitspaid"*"payrate") from "temptimesheetline" key join "temppayband" where "temptimesheetid" = @temptimesheetid and "includeinholidaypay" = 1) < 0 then
set "rv" = 0
end if;
return "isnull"("rv",0)
end