====== pears.GenerateKeyname ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."GenerateKeyname"( in "x" char(100) )
returns char(100)
begin
declare "w1" char(100);
declare "wn" char(100);
declare "c" char(1);
declare "i" integer;
set "x" = "trim"("x");
set "i" = "charindex"("char"(32),"x");
if "i" > 0 then
set "w1" = "left"("x","i"-1);
if "w1" in( 'mr','ms','miss','mrs','mr.','ms.','mrs.' ) then
set "x" = "right"("x","length"("x")-"i")
end if end if;
set "i" = "length"("x");
"loop1": loop
set "c" = "substr"("x","i",1);
if "c" = "char"(32) then
return "makekeyname"("right"("x","length"("x")-"i")+' '+"left"("x","i"-1))
end if;
set "i" = "i"-1;
if "i" <= 0 then
leave "loop1"
end if
end loop "loop1";
return "x"
end