====== pears.placementelementvalidV2 ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."placementelementvalidV2"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "bvalid" smallint,in "splacid" char(20),in "spersid" char(20),in "svacid" char(20),in "selementname" char(20),in "ismanager" smallint,in "isaccounts" smallint )
returns smallint
begin
declare "rv" smallint;
declare "l" long varchar;
declare "s" long varchar;
declare "i" integer;
declare "dt" char(1);
declare "subname" char(30);
declare "subchar" char(1);
if "isaccounts" is null then
set "isaccounts" = 0
end if;
if "isaccounts" <> 0 then
set "isaccounts" = 1
end if;
if "ismanager" is null then
set "ismanager" = 0
end if;
if "ismanager" <> 0 then
set "ismanager" = 1
end if;
set "l" = null;
if "bvalid" = 1 then
select "validationcheck" into "l" from "placementelementtype" where "name" = "selementname"
else
select "warningcheck" into "l" from "placementelementtype" where "name" = "selementname"
end if;
if "l" is null then
return(1)
end if;
"subloop": loop
set "i" = "patindex"('%{%}%',"l");
if "i" = 0 then
leave "subloop"
end if;
set "subname" = '';
"charloop": loop
set "subchar" = "substr"("l","i",1);
if "length"("l") = 1 then
set "l" = '' // In this case stuffing crashes the server
else
set "l" = "stuff"("l","i",1,'')
end if;
if "subchar" = '}' or "i" > "length"("l") then // The latter is precautionary
leave "charloop"
elseif "subchar" <> '{' then
set "subname" = "subname" || "subchar"
end if
end loop "charloop";
if "subname" = 'ACCOUNTS' then
set "s" = '(' || "str"("isaccounts") || '=1)';
set "dt" = 'B'
elseif "subname" = 'MANAGER' then
set "s" = '(' || "str"("ismanager") || '=1)';
set "dt" = 'B'
else
set "s" = "placementelementvalueV2"("splacid","spersid","svacid","subname");
if "subname" = 'PLACEMENTID' or "subname" = 'PERSONID' or "subname" = 'VACANCYID' then
set "dt" = 'S'
else
set "dt" = null;
select "datatype" into "dt" from "placementelementtype" where "name" = "subname"
end if end if;
if "s" is null then
set "s" = 'null'
else
set "s" = "replace"("s",'''','''''');
if "dt" = 'S' then
set "s" = '''' || "s" || ''''
else
if "dt" <> 'B' then
set "s" = 'cast(' || "s" || ' as real)'
end if
end if end if;
set "l" = "insertstr"("i"-1,"l","s")
end loop "subloop";
if "l" is null or "length"("l") = 0 then
return(1) // Assume valid
end if;
set "rv" = null;
set "l" = 'set rv=(select (if (' || "l" || ') then 1 else 0 endif) as bexpr)';
execute immediate "l";
return("rv")
end