Implement If condition in SSIS package

This is common requirement , you need to implement a If condition of If then else condition in a SSIS package flow. The example below illustrated it and implemented it with Precedence Constraints.

Problem Scenario:

there is a table in sql data source , If any records exist in this table then a Data Flow must transfer this data, Else a process must start.

Solution:

Create a variable in package scope name it cnt

Create an Execute SQL Task

Configure this task to return Select count(*) as cnt from table1 .

set the result set as Single row.

 In Result Set tab, add a result set with name cnt and map it with variable User::cnt

Add a Data Flow Task.

Connect green line from Execute Process Task to this data flow task,this line called Precedence Constraint and show the flow of tasks in package.

right click on this line and select Edit

In Precedence Constraint Editor, set evaluation operation as Expression

in Expression box write this : @cnt>0

add a Execute process task,

connect green line from execute process task to this new task , right  click on line and select edit

set evaulation operation as Expression, and expression box : @cnt<=0

 run the package.

This is overall plan schema:

Reza Rad on FacebookReza Rad on LinkedinReza Rad on TwitterReza Rad on Youtube
Reza Rad
Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for 12 continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand, Power BI Summit, and Data Insight Summit.
Reza is author of more than 14 books on Microsoft Business Intelligence, most of these books are published under Power BI category. Among these are books such as Power BI DAX Simplified, Pro Power BI Architecture, Power BI from Rookie to Rock Star, Power Query books series, Row-Level Security in Power BI and etc.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.

Leave a Reply