How to Pass variable to sql execute query?

Hello guys,

I am trying to create a table inside my sql database. I tried using input dialogue box so that I can dynamically give the name for the created table. For that purpose, how will I call value from “input dialogue box” to sql “Execute Query” ??
Thanks in advance!!!

1 Like


Try something like:

"Select * from " + tableName

where tableName is output from dialogue box. Alternatively you can click Edit Query, add parameter called i.e tableToSelect and call it in sql using @tableToSelect:

1 Like

hello @bstando
Thanks for the immediate reply… Actually, I tried both the methods and still there is some error. I will share the screenshots. Can you please have a look and help me correct it … (15.5 KB)

1 Like

@UnicornStark, if you using parameter type this query: “Select * into @dlg from Sheet1$ where 1=1” During runtime @dlg will be replaced with correct value.

1 Like

Hello @bstando
I used the same “SELECT * INTO @dlg FROM Sheet1$ where 1=1” command , but I am getting this error !

The variable type of “dlg” is generic. I tried ot make it “string”. But it is showing error.
btw… dlg is the dialog box output variable.

1 Like

Ok, delete dlg from parameters and paste into query this: “Select * into " + dlg.ToString + " from Sheet1$ where 1=1” Set dlg value type as GenericValue.

No luck… Tried that… Still getting same error .

Can you send logs from UiPath or this workflow?


Try the following:

“select * into” & dlg & “from [Sheet1$] where 1=1”


Here I am attaching the log , please have a look (5.7 KB)

hello @Lucas.Pimenta
Thanks. But its showing compiler error… I tried changing to “dlg.tostring” and at the end of execution, it is showing synatx error near the “table_name” . I am attaching the error screenshot, please have a look!
PS: I changed the table name from sheet1$ to sample in this particular workflow)

I am also in need of this solution. Done all steps, still no positive result. @ddpadil @badita @andrzej.kniola Can you guys also have a look at it please. thanx in advance.

Change dlg to dlg.ToString and try again.

It’s binary in C#. In it’s a string concatenation operator.
If defined for an operation it acts like a. Tostring call.
Although its not defined for this operation so your syntax is correct for GenericValue

1 Like

Oh, that’s interesting, didn’t know that & operator works this way in I assumed that it works like in C#. Thanks @andrzej.kniola

still no luck. I guess we have to try with stored procedure technique. But my knowledge in it is not much. Any help guyus!!!

You don’t have to use parameter dlg if you use variable dlg. Also you have error in your statement. Change "FROM to " FROM (with space between " and F)

Thanks a lot… Finally, it worked !

Hi, did you get it working? You should use + instead of &
For example “SELECT * INTO " + dlg + " FROM table WHERE …”

Yes just use + instead of &. Space after double quotes should be noted.