Sunday, August 28, 2016

SSIS For Loop Container Task

SSIS For Loop Container Task:

Why For Loop Container Task is Use ?
  • Name of the task itself explains most of of it !! For Loop container is falls under container and looping tasks
  • Use containers like the For Each Loop and For Loop to execute a set of tasks multiple times.
  • For example, you can loop over all the tables in a database, performing a standard set of operations like updating index statistics. 
    In short when we have to iteratively execute set of task we will insert all those task under For Loop Container and set the values accordingly
  • For loop task is the looping implementation of a task and also This task will evaluate an expression and loops through the process and until the evaluation goes to False.
The For Loop container uses the following elements to define the loop:
  1. An optional initialization expression that assigns values to the loop counters.
  2. An evaluation expression that contains the expression used to test whether the loop should stop or continue.
  3. An optional iteration expression that increments or decrements the loop counter.
How For Loop Container Task is look like ?
This is very first task in tab itself !!
image
Drag this out in your development plane
image
Features of For Loop Container Task
The following diagram shows a For Loop container with a Send Mail task. If the initialization expression is @Counter = 0, the evaluation expression is @Counter < 4, and the iteration expression is @Counter = @Counter + 1, the loop repeats four times and sends four e-mail messages.
image
image

How to use For Loop Container Task ?
Its very simple to use having actually three properties to set and its ready to use
1. InitExpression: Insert Initialization Expression here ,Initialization ensures that we are starting by setting out increment counter to 1.
2.EvalExpression: Insert Evaluation Expression here , For each iteration the evaluation expression checks to see if we have reached our maximum iteration count as set above when we defined @Counter.
3. AssignExpression: Insert an Assignment Expression here , This is used to increment the counter by one for each iteration of the loop, otherwise the loop would never finish.

What is alternative for For Loop Container Task ?
I think there is no alternative for this Directly ,If you ask still is there then there is we can call one package inside each other Smile..Think Think !!! 
Better not search for this Smile
Demonstration of using For Loop Container Task ?
1. Start in the package Control Flow, with no object selected . 
2. Right click the background in the package, and select Variables 
3. Add a variable called LoopIteration with the Int32 data type in the package.
snap
4. Add a For Loop Container to the package
5. Edit the For Loop Container by double-clicking it, or right-clicking it and choosing Edit. 
6. Set the InitExpression to @[User::LoopIteration]=0 
7. Set the EvalExpression to @[User::LoopIteration]<5 5="" br="" is="" loops="" nbsp="" number="" of="" run.="" style="margin: 0px; padding: 0px;" the="" to="" want="" where="" would="" you="">8.Set the AssignExpression to @[User::LoopIteration]=@[User::LoopIteration]+1 
9.Your settings should now look like this:
We can Use For loop Container as Do While Loop too as explained in following post :
Various Properties for For Loop Container Task ?
Following are various configurable properties for For loop container
image
Things to remember For Loop task
This is default properties of for loop task , If in a Loop container,the contents of that loop fail, then the entire container is failed at the same time.
Every now and then we need to create loops that do not fail when the contents fail – for example because failure is permitted or handled within the container.
We can set this too by allowing a loop to continue even if its contents have failed is to set theForceExecutionResult property to Success, and every iteration of the loop will be treated as successful, regardless of what happens during the loop.
Reference link for For Loop Container Task

No comments:

Post a Comment