How To Pass Dynamic Data To SQL Query From UiPath?

How to pass dynamic data to SQL query from UiPath ?

Pass dynamic data to SQL query, by following any of the below methods

  1. Passing variable to SQL query
  2. Passing parameter to SQL query


Approach #1: Passing Variable To SQL Query
  1. In order to pass variables to SQL query, variables must be declared first. In the below screenshot, three variables are declared and assigned values using assign activity before doing any SQL operation.
1.png
  1. The SQL query(INSERT/UPDATE/SELECT) needs to be modified to have those variable names as below. This can be done by clicking "Edit Query" option.
"INSERT INTO [dbo].[Table4] (Name,Value,Description)
VALUES ('"+Var_Name+"','"+Var_Value+"','"+Var_Description+"')"




Approach #2 : Passing Parameter To SQL Query

  1. The best way to pass the dynamic values to a SQL query is by using parameters. In order to use this option, click on "Edit query" in "Execute Query" or "Execute nonquery" activity.
  2. Click on the Parameters property in the Input section and pass the parameters. Refer the below screenshot.

2.png

  1. Enter the Arguments name. The arguments name need not match with the variables created, and then select the variable type.
3.png
  1. In the value section, enter the variable name because value of the variable will be accessed through the variable itself. Enter the name of the variable in the Value section.
4.png
  1. Next, the three parameters need to be passed in the query(Argument1, Argument2, Argument3), which are nothing but the Name of the parameters in the first column.
  2. By adding @ symbol as a prefix in each argument name as shown below, these parameters can be passed in the query. Refer the below screenshot.
5.png

2 Likes

Sorry, I am not seeing screenshots, which would be helpful.

In Approach #2, are you saying the variable value should be string ValueVariable =
“(@Argument1,@Argument2,@Argument3)” to make the query appear as:

“INSERT INTO [dbo].[Table4] (Name,Value,Description)
VALUES “+ValueVariable+”;”

Hello Glen,

Thank you for reaching out.
Please use the below link to refer the images.

https://uipath-survey.secure.force.com/CaseView/articles/Knowledge/How-to-pass-dynamic-data-to-SQL-query-from-UiPath?lang=en_US

Thanks,
UiPath Quality Team

1 Like

That looks great! Thank you!!

Seem like the approach 2 is not working for me, I tried using the first method and it works. For the second approach I will always insert null value into the database, may I know is it just me or someone have the same issue?

Is there any method by which we can update dynamic column names in parameter section…?? Actually my column name which inm updating in DB is dynamic n i m not understanding how to set it dynamic in parameter section

Is there any method by which we can update dynamic column names in parameter section…?? Actually my column name which inm updating in DB is dynamic n i m not understanding how to set it dynamic in parameter section

1 Like