Tuesday, November 13, 2018

SSIS - Foreach Loop Container

In this tutorial, we are going to learn how does For Loop Container work in SSIS package. The For Loop container defines a repeating control flow in a package. The loop implementation is similar to the For looping structure in programming languages. For Loop container groups set of tasks together and allows you to looping through the tasks in your package which is similar like for loop in any programming language. In case until a fixed count than you will use the “For Loop container”

Configuration editor has only two options For Loop and Expressions. 
  • InitExpression: This will initialize the loop with specified values.
  • EvalExpression: specifies an expression to stop the loop when the expression evaluates to false. This expression must evaluate to a Boolean. 
  • AssignExpression: specifies an expression that changes a condition in the same way each time the loop iterates.Which is optional one.
Drag and drop “For loop” container and configure as shown below

Difference between For Loop and Foreach Loop Container?
A For Loop container loops till a constant value. So for example if you want to loop until a value is 12 or less than 12 so for up-to fixed count you have to use For Loop container.
Whereas Foreach Loop container loops through collection so this collection can files in a folder or collection can be in record set.
Foreach loop - Foreach loop container actually loop through a collection. Now this collection row in a record set files in a folder.
Foreach Loop Container Task: When there is dependency of number of time task should execute on data such as files, variables we will use this.The Foreach Loop container defines a repeating control flow in a package. The loop implementation is similar to Foreach looping structure in programming languages. In a package, looping is enabled by using a Foreach enumerator. The Foreach Loop container repeats the control flow for each member of a specified enumerator.

In short, a For Loop Container uses a loop condition that is defined by expressions whereas Foreach Loop Container iterates through a collection of objects.

With a Foreach Loop Container, we can perform variable mapping as well, which would be useful for tasks within the loop.

1 comment:

  1. Wonderful, what a web site it is! This blog presents helpful facts to me, keep it up. My site is content marketing tuyen dung tai ha noi