How to pass a variable in an SQL query

Hello all, I am trying to execute a dynamic SQL query (SQLite), which looks like this:

“SELECT address
FROM Clients
WHERE client = ‘(varClientId)’”

(varClientId) is a place holder for what would be my string variable.

Except it’s wrong, because I get an error. I already tried ‘$[variable_name]’, but it returns an empty result.

Furthermore I tried :

“SELECT address
FROM Clients
WHERE client = “+”’”+varClientID+"’"+"

But seems like you have to execute one string command.

Thank you,

Hello,
Have you tried making a string variable and then using that as the query.This is my perferred way to run sql queries.

queryStr = “SELECT address FROM clients WHERE client = “+”’”+varClientID+”’"+"
Then our your dynamic SQL query use queryStr as the string.

2 Likes

Hello Sergio,

I believe this will work for you:
"Select address From Clients Where client = '" + varClientID + "'"

Here’s the output if it is run in a log message activity:
image

Hi @eccprog

Here is the sample to pass the parameter to the query.

Regards
Balamurugan.S

3 Likes

Thank you all, this worked!

1 Like

Capture

do you know why i’m getting this?

Hi @r.saleh,

It seems dependencies are missing in your workflow for that you need to install packages go to manage package install - Uipath.Database.Activities

Thanks,
Neelima.