How to pass dynamic data to SQL query from UiPath ?
Pass dynamic data to SQL query, by following any of the below methods
- Passing a variable to SQL query
- Passing a parameter to SQL query
Approach #1: Passing Variable To SQL Query
- 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 the "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. To use this option, click on "Edit query" in the "Execute Query" or "Execute nonquery" activity.
- Click on the Parameters property in the Input section and pass the parameters. Refer to the below screenshot.
- Enter the arguments names. The arguments names need not match with the variables created, and then select the variable type.
- In the value section, enter the variable name because the 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 the @ symbol as a prefix in each argument name as shown below, these parameters can be passed in the query. Refer to the below screenshot.