====== pears.PostCodePart ======
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"."PostCodePart" IS
{create function PostCodePart
/* Application Maintained Function / Procedure - DO NOT EDIT*/
( in postcode char(20),in part char(20) )
returns char(20)
deterministic
begin
declare i integer;
declare area char(20);
set postcode = trim(postcode);
set i = patindex('%[0-9]%',postcode);
if i = 0 then
return null
end if;
set area = substr(postcode,1,i-1);
if part = 'area' then
return area
end if;
set postcode = stuff(postcode,1,i-1,null);
set i = patindex('%[^0-9]%',postcode);
if part = 'district' then
return area+"left"(substr(postcode,1,i-1),2)
end if
end
}