Use comma separated variable to produce a SQL query string

Hello,

i have a situation in which an user should instantiate a variable done like that:

Locations => 1 , 2 , 5 , 9

Doing some manipulation i have to use this information to make a column with a sql query like that:

select staticfield, anotherstaticfield, hellofield, “dynamicfields” from table where “dynamiccondition”

where

dynamicfields is: Location1, Location2, Location5, Location 9

dynamiccondition is: (Location1 <>0 or Location2<>0 OR location5<>0 or Location9 <>0)

I did this:

1- created a column by the variable, removing the “spaces” using “Column Expressions” block

2-splitted the cell by the “comma” separator, so i obtain something like Location[0] =>1 Location[1]=>2, Location[2] => 5, Location[3] => 9

3- initialized empty column like dynamicselect=“” and dynamicwhere=“”

4- tried with a Column List Loop Start / Loop End (Column Append)

5- used inside the loop a Column Expression that should “replace” dynamicselect and dynamicwhere like that: dynamicselect= dynamicselect + “, Location”+column(“currentColumnValue”), and something similar about the WHERE condition

THE PROBLEM:

this column expression (but i tried also with math formula) doesn’t append on the original column “dynamicselect” the new values, but for each column it add a “dynamicselect (Item N)” element with just that value and i tried many many methods to avoid that without success.

Expectation:

Step 1: dynamicselect passing from “” to “, Location1”

Step 2: dynamicselect passing from “, Location1” to “, Location1, Location 2”

Step 3: dynamicselect passing from “, Location1, Location 2” to “, Location1, Location 2, Location 3”

Results:

Step 1: dynamicselect stayed “”, found a created column dynamicselect (Item 0) with value “, Location1”

Step 2: dynamicselect stayed “”, found a created column dynamicselect (Item 1) with value “, Location2”

and so on… at the end i have dynamicselect, dynamicselect (Item 0), dynamicselect (Item 1), dynamicselect (Item 2)

Of course i selected the “replace column” checkbox instead of create new column

Have you some advice for me? Maybe a totally different solution, or maybe some explanation on how to do it with the loop?

Thank you