Chapter 42

Using For Loop Containers to Repeat Control Flow Tasks

Loops are a great tool that can be used in many programming languages. They provide a way to iterate over selected code repeatedly until it is conditionally told to stop. For example, in T-SQL a While loop is constructed so that a statement is repeated until a boolean expression evaluates as false. The For Loop Container in SSIS works much the same way.

A common reason that you might use the For Loop Container is if you have a set of Control Flow Tasks that need to be run until a condition has been met. For example, in the Try It section of this lesson, you use a For Loop Container to check to see if a table has any rows of data. If the table has no records, the loop continues to iterate until it finds that at least one row is present.

When you use a For Loop Container, you first create a variable that the container can use to store an expression value of how many times the container has completed a run. The container runs three separate expressions at run time to formulate the loop. These three expressions require only one variable because the expressions change the same variable value each time they evaluate.

To configure the For Loop Container, drag it on the design surface and double-click the top portion of the container to open the editor. Here you see the InitExpression, EvalExpression, and AssignExpression properties:

  • InitExpression—This expression sets the initial value of the variable, so if you want the ...

Get Knight's Microsoft SQL Server 2012 Integration Services 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.