====== pears.commathousands ======
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"."commathousands" IS
{create function commathousands
/* Application Maintained Function / Procedure - DO NOT EDIT*/
(in d double)
returns char(20)
begin
declare rv char(20);
declare s char(20);
declare t char(20);
declare i integer;
declare c char(1);
if d is null then
return null
end if;
if d < 0 then
set d=abs(d);
set c='-'
else
set c=''
end if;
set rv='';
set s=trim(str(d,20,0));
set i=-1;
lbl: loop
set t=substr(s,i,-3);
if t = '' then
leave lbl
end if;
if rv <> '' then
set rv=','+rv
end if;
set rv=t+rv;
set i=i-3
end loop lbl;
return(c+rv)
end
}