====== pears.SetQuestSubMenuSelection ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create procedure "pears"."SetQuestSubMenuSelection"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "stagloc" char(3),in "stagid" char(3),in "sparentid" char(20),in "svalue" long varchar )
begin
declare "i" integer;
declare "stagchoiceid" char(4);
declare "schoicevalue" long varchar;
declare "stagtype" char(1);
select "tagtype" into "stagtype" from "tag" where "tag"."taglocation" = "stagloc" and "tag"."tagid" = "stagid";
if "charindex"("char"(10),"svalue") > 0 then -- Do not want to risk having line feeds
set "svalue" = "replace"("svalue","char"(10),'')
end if;
set "svalue" = "string"("svalue","char"(13),' '); -- Ensure it has trailing CR and some extra space so that STUFF does not return emptry string and fall over
loop
set "i" = "charindex"("char"(9),"svalue");
if "i" = 0 then
return
end if;
set "stagchoiceid" = "trim"("left"("svalue","i"-1));
set "svalue" = "stuff"("svalue",1,"i",'');
set "i" = "charindex"("char"(13),"svalue");
set "schoicevalue" = "left"("svalue","i"-1);
set "svalue" = "stuff"("svalue",1,"i",'');
if "stagchoiceid" <> '' then
call "setquestanswer"("stagloc","stagid","schoicevalue","sparentid","stagchoiceid")
end if
end loop
end
go
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."SetQuestSubMenuSelection" IS
{create procedure SetQuestSubMenuSelection
/* Application Maintained Function / Procedure - DO NOT EDIT*/
(in stagloc char(3),in stagid char(3),in sparentid char(20),in svalue long varchar)
begin
declare i integer;
declare stagchoiceid char(4);
declare schoicevalue long varchar;
declare stagtype char(1);
select tagtype into stagtype from tag where tag.taglocation=stagloc and tag.tagid=stagid;
if charindex("char"(10),svalue) > 0 then -- Do not want to risk having line feeds
set svalue=replace(svalue,"char"(10),'')
end if;
set svalue=string(svalue,"char"(13),' '); -- Ensure it has trailing CR and some extra space so that STUFF does not return emptry string and fall over
loop
set i=charindex("char"(9),svalue);
if i = 0 then
return
end if;
set stagchoiceid=trim("left"(svalue,i-1));
set svalue=stuff(svalue,1,i,'');
set i=charindex("char"(13),svalue);
set schoicevalue="left"(svalue,i-1);
set svalue=stuff(svalue,1,i,'');
if stagchoiceid <> '' then
call setquestanswer(stagloc,stagid,schoicevalue,sparentid,stagchoiceid)
end if
end loop
end
}