How to pass dynamic data to SQL query from UiPath ?
Pass dynamic data to SQL query, by following any of the below methods
- Passing variable to SQL query
- Passing parameter to SQL query
Approach #1: Passing Variable To SQL Query
- 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.
- 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
- 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.
- Click on the Parameters property in the Input section and pass the parameters. Refer the below screenshot.
- Enter the Arguments name. The arguments name need not match with the variables created, and then select the variable type.
- 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.
- 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.
- 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.