Add uipath variable in middle of SQL query

I’m looking to connect to SQL db in order to get data with this query (which works just fine):

"select Top 3 * from"

My issue: I would need to edit that query dinamically based on a variable (stored in UiPath). I’ve tried this query bellow, but doesn’t work.

"select " + variable + " * from"

I’ve tried this combination which again works well. But I need to add my variable in the middle of the query.

"select Top 3 * from"+variable

Use a variable for your query, for example strSQLquery.
Before your execute query activity, assign strSQLquery = “select " + variable + " * from”


Incorect sintax.

I’m not familiar with SQL but have worked with SOQL. I have just copied your query code.
Make sure that you do not have extra spaces in your "variable’ as you already have one after “select” and before “*”. You can also try using & instead of +, like:
strSQLquery = “select " & variable.trim & " * from”


Try this:

"select "" +' variable' + "" * from"


"select Top" +Var +" * from"


1 Like