Integration Services (SSIS) Variables
Variables store values that a SQL Server Integration Services package and its containers, tasks, and event handlers can use at run time. The scripts in the Script task and the Script component can also use variables. The precedence constraints that sequence tasks and containers into a workflow can use variables when their constraint definitions include expressions.
You can use variables in Integration Services packages for the following purposes:
-
Updating properties of package elements at run time. For example, you can dynamically set the number of concurrent executables that a Foreach Loop container allows.
-
Including an in-memory lookup table. For example, a package can run an Execute SQL task that loads a variable with data values.
-
Loading variables with data values and then using them to specify a search condition in a WHERE clause. For example, the script in a Script task can update the value of a variable that is used by a Transact-SQL statement in an Execute SQL task.
-
Loading a variable with an integer and then using the value to control looping within a package control flow. For example, you can use a variable in the evaluation expression of a For Loop container to control iteration.
-
Populating parameter values for Transact-SQL statements at run time. For example, a package can run an Execute SQL task and then use variables to dynamically set the parameters in a Transact-SQL statement.
-
Building expressions that include variable values. For example, the Derived Column transformation can populate a column with the result obtained by multiplying a variable value by a column value.
Integration Services supports two types of variables: user-defined variables and system variables. User-defined variables are defined by package developers, and system variables are defined by Integration Services. You can create as many user-defined variables as a package requires, but you cannot create additional system variables.
All variables—system and user-defined—can be used in the parameter bindings that the Execute SQL task uses to map variables to parameters in SQL statements. For more information, see Execute SQL Task and Parameters and Return Codes in the Execute SQL Task.
Note
|
|---|
|
The names of user-defined and system variables are case sensitive. |
You can create user-defined variables for all Integration Services container types: packages, Foreach Loop containers, For Loop containers, Sequence containers, tasks, and event handlers. User-defined variables are members of the Variables collection of the container.
If you create the package using SSIS Designer, you can see the members of the Variables collections in the Variables folders on the Package Explorer tab of SSIS Designer. The folders list user-defined variables and system variables.
You can configure user-defined variables in the following ways:
-
Provide a name and description for the variable.
-
Specify a namespace for the variable.
-
Indicate whether the variable raises an event when its value changes.
-
Indicate whether the variable is read-only or read/write.
-
Use the evaluation result of an expression to set the variable value.
-
Create the variable in the scope of the package or a package object such as a task.
-
Specify the value and data type of the variable.
The only configurable option on system variables is specifying whether they raise an event when they change value.
A different set of system variables is available for different container types. For more information about the system variables used by packages and their elements, see System Variables.
For more information about real-life use scenarios for variables, see Use Variables in Packages.
You can configure user-defined variables by setting the following properties in either the Variables window or the Properties window. Certain properties are available only in the Properties window.
Note
|
|---|
|
The only configurable option on system variables is specifying whether they raise an event when they change value.
|
You can set properties through SSIS Designer or programmatically.
For more information about the properties that you can set in SSIS Designer, see Variables Window.
To learn more about variable properties, and for more information about programmatically setting these properties, see Variable.
Note