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.![add-assign-activity-bfr-non-query-rpa-uipath](upload://wv3v7B1dAS6nLjijUfAfpn54a8m.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.

![edit-sql-rpa-uipath](upload://xBdEFZWMThpwwjHW4whhNdinj0l.png)

  1. Enter the Arguments name. The arguments name need not match with the variables created, and then select the variable type.

![parametrs-name-rpa-uipath](upload://tYfAh7n9DhHzCbAz0BsJFw20Spm.png "parametrs-name-rpa-uipath")

  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.![passing-parameters-rpa-uipat](upload://fz2EHyQZYls5Y1i51IsIEtKbFsr.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.![passing-variable-as-parameters-rpa-uipath](upload://fEVS7DmBgXempLZVOHsNwSDos9d.png)