SSIS - [How To Use Precedence Constraint]

Scenario:

We are loading data from source file to our SQL Server table.  After the load we want to send email if number of records loaded are more than 5.

Solution:

We will be using Precedence Constraint with expressions to handle this scenario. Here is step by step approach.

Step 1:
Create a variable RowCnt with scope= Package level as shown below. We will be using this variable in expressions to make decision to send email or not.


Step 2:
Bring data flow task on Control Flow pane and then build as shown below. It should be extracting from Source File, Row Count Transformation will be using RowCnt variable to capture  rows moved between source and destination. Use OLE DB Destination to insert data into SQL Table.



 Step 3:
Choose Control Flow and connect Data flow task to Send Mail Task. After connecting them, double click on green connection ( Precedence constrain) and write expression as shown below.



 We are considering two things here, Once Success of Previous Task and Expression should be true. If both will be true then Send Mail Task will be execute else It will stop at Data Flow Task.