How to Pass variable to sql execute query?

datatable
database
uiautomation
sql
variable

#1

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” ??
URGENT HELP REQUIRED!!!
Thanks in advance!!!


#2

Hi

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: https://www.uipath.com/activities-guide/execute-query


#3

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 …
s.zip (15.5 KB)


#4

@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.


#5

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.


#6

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.


#7

No luck… Tried that… Still getting same error .


#8

Can you send logs from UiPath or this workflow?


#9

Hello!

Try the following:

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

Regards,


#10

Here I am attaching the log , please have a look
2017-09-19_Execution.zip (5.7 KB)


#11

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)


#12

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.


#13

Change dlg to dlg.ToString and try again.


#14

It’s binary in C#. In vb.net 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


#15

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


#16

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


#17

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)


#19

Thanks a lot… Finally, it worked !


#20

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


#21

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