Variables, Parameters and SQL IN Statements (UiPath)

Good morning everyone,

I currently have the following SQL query that runs successfully.

SELECT * FROM DB.TABLENAME

WHERE ACCOUNT_NUMBER IN (123,654,234,876).

The above query works when I run it outside of UiPath but I am having issues when running it within UIPath.

In UiPath, I have added the account numbers to a string variable like below. and then feed the variable into the SQL query in UiPath like shown below :slight_smile:

str_AcctNum = 123,654,234,876

SELECT * FROM DB.TABLENAME

WHERE ACCOUNT_NUMBER IN ’ “+str_AcctNum+” ’

It is not causing an error BUT it is returning NULL results in the output spreadsheet.

Now if I change the select statement to take in one account number at a time like shown below, the query is returning results:

str_AcctNum = 123

SELECT * FROM DB.TABLENAME

WHERE ACCOUNT_NUMBER = ’ “+str_AcctNum+” ’

The question is, how do I need to format this query in order for it to be able to take in multiple account numbers using the IN statement.

Hi,

Use the below:

SELECT * FROM DB.TABLENAME
WHERE ACCOUNT_NUMBER IN +str_AcctNum

Quotes are not required i guess as its integer.

Hi Arun,

Your response was a solution if ALL of my Account ID’s are integers ( I tried it ).

Unfortunately, some of mine have strings (for example B-123 account number) . With the help of a co-worker, we came to the solution posted below.

First things first, I was passing an argument instead of a variable into the SQL query so that was the first issue. I instead assigned the Argument to a variable and then passed in the variable.

The second issue was I fixed the query to look like below and that worked :).

str_AcctNum = 1(23, B-132, 5393)

SELECT * FROM DB.TABLENAME

WHERE ACCOUNT_NUMBER IN ( “ + str_AcctNum + ” )

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.