mult-value parameter

Post Reply
sourceuno
Posts: 225
Joined: Mon Apr 09, 2001 3:58 pm

mult-value parameter

Post by sourceuno »

How can I feed a script a multiple value parameter? I want to do something like this:

c:\inetpub\scripts\texis inparam=1,2,3 testscript

Is this the correct way of sending this parameter? I want eventually use these values in a where clause inside the script like in the following statement:

<sql "select * from tbl where val in $inparam"></sql>
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

mult-value parameter

Post by Kai »

You can assign a multi-value variable on the command line by assigning to it multiple times, eg.:

texis inparam=1 inparam=2 inparam=3 testscript

See http://www.thunderstone.com/site/vortexman/node190.html for details.

However, your SQL syntax will be a problem, because only the first value of parameters is passed to <SQL> statements, and IN expects a parenthetical list of values, with the parentheses in the *statement* itself, eg.:

"... where val in ($x,$y,$z)"

where $x, $y and $z are single-value variables.

While it is true that multi-value *string* parameters to <SQL> are parenthesized (see http://www.thunderstone.com/site/vortexman/node38.html for details), this is a Metamorph (LIKE query) syntax, ie. the parens are part of the *parameter*, while IN expects parens in the *statement*.

An alternate syntax for IN for string multi-values is a strlst. You can convert a multi-value Vortex var to a strlst and pass it to IN thusly:

<sum "%s," "" $inparam>
<substr $ret 1 -1>
<$ret = (convert($ret, 'strlst' ))>
<SQL "select ... from tbl where val in $ret"></SQL>

However, the left-side of the IN should also be a varchar (string) in this case.
Post Reply