====== pears.GetCompanyGroupHead ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."GetCompanyGroupHead"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "CompID" char(20) )
returns char(20)
begin
declare "coid" char(20);
declare "oldcoid" char(20);
declare "lc" integer;
select "parentcompanyid" into "coid" from "company" where "companyid" = "compid";
if "coid" is null then
return "compid"
end if;
set "oldcoid" = null;
set "lc" = 1;
while("coid" is not null) and("lc" < 1000) loop
set "oldcoid" = "coid";
set "lc" = "lc"+1;
select "parentcompanyid" into "coid" from "company" where "companyid" = "coid"
end loop;
return "oldcoid"
end