====== pears.PersonAvailableAtTime ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."PersonAvailableAtTime" IS
{create function PersonAvailableAtTime
/* Application Maintained Function / Procedure - DO NOT EDIT*/
(in sPersonid char(20),in dShiftDate date,in tShiftFrom time,in tShiftTo time,in iCheckExplicitlyAvailable smallint)
returns char(1)
begin
declare foundState char(1);
set foundstate=null; -- If we return null, we have found no explicit unavailability or availability
-- First check for all day unavailability
select first state into foundstate from tempshift where state not in( 'A','C') and
personid = spersonid and shiftdate = dshiftdate and(timefrom is null or timeto is null);
if foundstate is null then -- Look for non-concurrent employments
select first 'W' into foundstate from employment where
isnull(concurrent,0) = 0 and personid = spersonid and startdate <= dshiftdate and(leavedate is null or leavedate >= dshiftdate)
end if;
if foundstate is null then
set foundstate=personavailableforplaniterate(spersonid,dshiftdate,tshiftfrom,tshiftto,icheckexplicitlyavailable,'')
end if;
return foundstate
end
}