pears.commathousands

Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.

Original SQL

CREATE FUNCTION "pears"."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