ssis
  1. ssis-for-loop-container

For Loop Container - (SSIS Control Flow)

The For Loop Container provides looping functionality within the SSIS control flow. It is used to repeat a set of tasks or operations for a specified number of times or until a condition is met.

Syntax

For Loop Container:
    InitExpression
    WhileExpression
    EvalExpression
    <Tasks to repeat>
End For

Example

Let's say we have a set of tasks that needs to be performed for each record in a dataset. The For Loop Container can be used to repeat these tasks for each record until all records have been processed.

For Loop Container:
    InitExpression = 0
    WhileExpression = @[User::RecordCount] > 0
    EvalExpression = @[User::RecordCount] = @[User::RecordCount] - 1

    <Tasks to repeat>
      ...
End For

In this example, @[User::RecordCount] is a variable that stores the total number of records to be processed. The InitExpression initializes a counter variable to zero. WhileExpression checks whether the counter is less than the total number of records. If it is, the loop continues. The EvalExpression subtracts one from the counter variable each time the loop is executed.

Output

The output of a For Loop Container depends on the tasks contained within it. The container will execute the specified tasks repeatedly until the loop condition is no longer met.

Explanation

The For Loop Container allows you to specify a set of SSIS tasks to perform repeatedly until a specific condition is met. The InitExpression is used to initialize the loop counter, the WhileExpression is used to evaluate the loop condition, and the EvalExpression is used to modify the loop counter each time the loop executes. The tasks contained within the loop body are executed repeatedly until the loop condition is no longer met.

Use

The For Loop Container is used to repeat a set of tasks or operations for a specified number of times or until a condition is met. It is commonly used in scenarios where you need to perform a set of SSIS tasks repeatedly for each record in a dataset.

Important Points

  • The InitExpression initializes the loop counter variable.
  • The WhileExpression evaluates the loop condition.
  • The EvalExpression modifies the loop counter variable.
  • The container will execute the contained tasks repeatedly until the loop condition is no longer met.
  • The For Loop Container can be nested within other containers.

Summary

The For Loop Container is a valuable tool in the SSIS toolbox. It allows you to repeat a set of tasks or operations for a specified number of times or until a condition is met. By using the InitExpression, WhileExpression, and EvalExpression, you can create complex looping scenarios within the SSIS control flow.

Published on: