Convert Comma Separated String to Array

schizek

New Member
I am passing user selected variables through a multi-select listbox. I need to get these variables into an array to then use in my dynamic query. Currently it appears they are concatenating each selected option together in a comma separated string. Any ideas on how to get them into an array?

For example, if the listbox shows a list of 20 locations, the user can select as many as they want. If they select location #9, 15, and 18 they then get passed through the querystring as "...?location=9&location=15&location=18". Then I assigned it to a variable...

Code:
DEF VAR location AS CHAR.
SET location = get-value('location').
If you display location it outputs the string "9,15,18". I then need to run these three locations through a where statement... "WHERE table.location = '9' OR table.location = '15' OR table.location = '18'". The best solution I can think of is to use an array.

If anyone has any suggestions it would be much appreciated. Thanks!
 

FrancoisL

Member
You can use the ENTRY() function.


Usage: ENTRY(<Position>, <String> , <Seperator>)

separator is optional and will use the comma if not specified. The position starts at 1.

so you could do :

Table.Field = ENTRY(1, location) OR Table.Field = ENTRY(2, location) OR Table.Field = ENTRY(3, location)

You can know the number of entries in your string with NUM-ENTRIES .
 
Top