Run SQL Query Using String List Variable

I am attempting to run a SQL query that uses a string variable that is a list of values. The query is a search where I use “WHERE x IN ______” where the blank is the string variable. I create this string variable by concatenating things together. For example, the string would look something like this (‘0000000’, ‘1111111’, ‘2222222’).

When run the query with that exact string, it runs correctly. However, when I put that string into a variable and pass it as a parameter into the Execute Query activity, it gives me an error regarding the variable.

Has anybody had any success with running a query and this type of string variable? Thanks

@jpreziuso, just to check what the query becomes at run time, assign the query to a string variable (copy and paste the query you are trying to run in an assign activity) and this way you will be able to get to the error.
You can use your preferred way though - write line, write to a text file etc, to see the actual run-time query.
I have found this useful to debug queries.

Hi - thank you for the input. Do you think you could post a screenshot example of what you mean? I have written out the query in a write line and it looks how I want to. But adding the variable causes an issue.

Should I have the whole query be a variable and then execute that variable? Because right now I have just the one parameter as a variable. Like “SELECT * WHERE Num IN @VARIABLE

And @VARIABLE is my list of strings

@jpreziuso - can you try copying the query from run line and executing it using a client (outside of UiPath)? Does it run as expected?

Also, try this - "SELECT * FROM tablename WHERE Num IN ("+variable+") " , assuming the variable is a string variable.