Subject Re: parameter for the IN statement in a stored procedure
Author casibart
Wow, ok, but can this also be done with your code?

1. Parse the inputstr varchar(50) variable

2. Sum up the single arguements to the val variable, so the val
variable will look like this: ("200","201","202")

3. execute the statement with the IN statement like

execute statement 'SELECT r1 FROM t1 WHERE x1 IN ' || val into :r;


I think I have some obsession with that IN statement :)
What do you think, will this work?
Thank you.



> But you could pass a comma-separated string and the number of
arguments in your list, and use EXECUTE STATEMENT for each implicit
OR condition, to get your result set cumulatively, something like
this:

>
> create procedure blah(inputstr varchar(50), numargs smallint)
> returns (r integer)
> as
> declare comma char = ','
> declare val varchar(9) = '';
> declare suspend_now char = 'N';
> declare currentchar char;
> begin
> while (numargs > 0) do
> begin
> currentchar = substring(inputstr from 1 for 1);
> if (( currentchar = comma)
> or (currentchar = '')
> or (currentchar = ' ')
> or (currentchar is null)) then
> suspend_now = 'Y';
> else
> val = val || currentchar;
> if (suspend_now = 'Y') then
> begin
> suspend_now = 'N';
> execute statement 'SELECT r1 FROM t1 WHERE x1 = ' || val
into :r;
> suspend;
> val = '';
> numargs = numargs - 1;
> if (currentchar = comma) then
> inputstr = substring(inputstr from 2); -- jump over comma
> end
> inputstr = substring(inputstr from 2);
> end
>
> ./hb
> end