====== pears.PlacementDayWorked ======
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"."PlacementDayWorked" IS
{create function PlacementDayWorked
/* Application Maintained Function / Procedure - DO NOT EDIT*/
( in placid char(20),in pdate date )
returns smallint
begin
declare bcanc tinyint;
declare nhrs real;
declare d smallint;
declare bdayticked tinyint;
declare banyticked tinyint;
if placid is null then
return 1
end if;
select first v.WorkCancelled,v.WorkHours into bcanc,nhrs
from PlacementDayVariation as v
where v.placementid = placid and v.VariationDate = pdate;
if bcanc = 1 then
return 0
end if;
if nhrs is not null then
if nhrs > 0 then
return 1
else
return 0
end if
end if;
set d = dow(pdate)-1;
select(case d when 0 then worksunday when 1 then workmonday when 2 then worktuesday when 3 then workwednesday when 4 then workthursday when 5 then workfriday when 6 then worksaturday end),
isnull(worksunday,workmonday,worktuesday,workwednesday,workthursday,workfriday,worksaturday)
into bdayticked,banyticked from placement where placementid = placid;
if banyticked is null then
return 1
else
return isnull(bdayticked,0)
end if
end
}