Updated March 15, 2023
What is SSIS expression?
- We can normally define an expression term as an arrangement of symbols-identifiers, functions, operators, and literals that produce only one data value. Further, a simple expression will be only one constant, variable, or function. However, we can make an expression more compound type often used by implementing various functions and operators and referencing numerous variables and columns.
- But in SSIS services, we can say that expressions are applied to state conditions for forming and updating values in the data columns, CASE statements, allocating values to variables, modifying or occupying properties at the time of execution, describing constraints in the precedence constraints, and delivering the expression implemented by For Loop container.
Create SSIS expression task
Let us view how to create an expression task for SSIS Connection Manager as follows:
In this illustration, for a Connection Manager, we will set up an expression by forming two new variables for storing the values since the name of the server and the database will be unlike, which depends on the target environment. After that, the ConnectionString will be established at the time of execution centered on these variables’ values. So, first, one needs to choose the Connection Manager and then the property window for adding the required expression as:
Again, click on the button available on the expression property, which will help to open other dialog boxes for selecting the property specified for the Connection Manager.
Choosing ‘ConnectionString’ specified as the property, one needs to click the expression button, which will further load or open the Expression Builder for creating the expression. As displayed in the below image, a connection string is built up by adding the variables values of the database and the server:
Here, an expression can be created now and can be evaluated or verified as a true or false one.
SSIS Expression Elements
Let us discuss a few components or, say, elements that can implement expressions in Integrated services:
1. Variables can apply expression for setting their value. For instance, GETDATE() helps to set the variable value to the current date.
2. Unlike destinations, the Conditional Split transformation uses a decision structure that depends on expressions for aiming data rows.
Such a used expression here should calculate to TRUE or FALSE type. For instance, we can route rows that match the condition to different output in the provided expression like “Column1 > Column2”.
3. The Derived Column transformation implements values generated by expressions for either populating new columns or updating prevailing columns in a data flow. For instance, the expression Column1 + “XYZ” can be applied to create a new value or even modify a value with the help of a concatenated string.
4. The For Loop container can also implement expressions for making the initialization, valuation, and incrementing statements that the looping structure implements. For instance, the expression such as @Counter = 1 sets the loop counter.
5. Precedence constraints also can apply expressions for identifying the conditions which recognize whether the constrained job or container in a package executes. Here, the expression implemented should be able to estimate TRUE or FALSE. For instance, the provided expression like @A > @B will equate to two kinds of user-defined variables for defining whether the constrained task executes or not.
Use of SSIS expression
- SSIS Expressions can modify container packages’ properties, like the Foreach Loop and the For Loop, package, tasks, and project-level connection log providers, managers, and even Foreach enumerators. For instance, the string can be assigned as a property expression “Localhost.AdventureWorks” to the connectionName property specified in the Execute SQL job.
- In the Integration Services, SSIS expressions are used for stating conditions to create and update values in the columns of data; for CASE statements, allocate values to variables.
- Also, SSIS expression is applied for stating constraints in precedence constraints, altering or occupying properties at the time of the run, and giving the expressions implemented by For Loop container.
- Expression is used for control flow and data flow consisting of expression for SSIS Expression builder, SSIS Expression for variables, Connection Manager in SSIS, SSIS expression for container or package, etc.
SSIS expression Common examples
Let us see the visual representation of a specified Expression:
In the SSDT (SQL Server Data Tools), a minor image is displayed to denote the object using an expression on the Task/ Connection Manager/ Container. View the example below, which shows that an expression is applied in the Connection Manager:
Using expression defined for an SSIS Container:
We have assumed that there is a root folder, and we will iterate via the files available in the folder to aspect for the CSV file and then load the data record into the table. One of the finest options for completing this type of task is the ForEach Loop container.
Now, we will view how the expression can be implemented to configure the file extension and the folder at run time.
The folder’s position can vary depending on the environment (such as Test, Dev, and prod); therefore, it is preferred to set up the folder’s position along with the file extension at the execution time.
After this, you must choose the property option “Directory” and click the expression button.
Now, in the expression window, you can add the Folder variable name and then calculate as displayed below:
As soon as the specified expression is added, you can see the expression in the main window:
Conclusion
- An expression depends on an expression language along with the expression evaluator, which analyses the specific expression and identifies whether the expression confirms the rules of the expression language or not.
- This information described on SSIS Expression can benefit you to begin the implementation of expression in developing the SSIS package. Once the basics are familiar, one can extend the expression, including the operators and functions.
Recommended Articles
This is a guide to SSIS Expression. Here we discuss the What is SSIS expression, Create SSIS expression task, SSIS Expression Elements, and examples. You may also have a look at the following articles to learn more –