====== pears.dateToNearest ====== 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"."dateToNearest" IS {create function dateToNearest /* Application Maintained Function / Procedure - DO NOT EDIT*/ ( in pDate date,in pUnit char(1) ) returns date deterministic begin case pUnit when 'd' then return pDate when 'w' then while dow(pDate) <> 2 loop set pDate = pDate-1 end loop; return pDate when 'm' then return ymd(year(pDate),month(pDate),1) when 'q' then return ymd(year(pDate),floor((month(pDate)-1)/3)*3+1,1) when 'y' then return ymd(year(pDate),1,1) end case end }