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 booking.dbo.booking"

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 booking.dbo.booking"

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 booking.dbo.booking"+variable

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

image

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 booking.dbo.booking”

Hey!

Try this:

"select "" +' variable' + "" * from booking.dbo.booking"

OR

"select Top" +Var +" * from booking.dbo.booking"

Regards,
NaNi

1 Like