Thursday, 6 November 2014

Foreach Loop Container,ControlFlow,SSIS


Foreach Loop Container:
For each loop is used to perform the dynamic looping of files to be stored in the destination in SSIS. Like we can retrieve 10 excel sheets or 10 text files or any type of files from an existing folder or by creating folder. Just we need to pass the path of the path and mention the Extensions of the files like * .xls ,*.txt …
In Briefly about For Each Loop Container…
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.
SQL Server 2005 Integration Services (SSIS) provides the following enumerator types:
  • Foreach File enumerator to enumerate files in a folder. The enumerator can traverse subfolders. For example, you can read all the files that have the *.log file name extension in the Windows folder and its subfolders.
  • Foreach from Variable enumerator to enumerate the enumerable object that a specified variable contains. The enumerable object can be an array, an ADO.NET DataTable, an Integration Services enumerator, and so on. For example, you can enumerate the values of an array that contains the name of servers.
  • Foreach Item enumerator to enumerate items that are collections. For example, you can enumerate the names of executables and working directories that an Execute Process task uses.
  • Foreach Nodelist enumerator to enumerate the result set of an XML Path Language (XPath) expression. For example, this expression enumerates and gets a list of all the authors in the classical period: /authors/author [@period='classical'].
The Foreach loop uses the Foreach File enumerator, and the File System task is configured to copy a file. If the folder that the enumerator specifies contains four files, the loop repeats four times and copies four files.
You can use a combination of variables and property expressions to update the property of the package object with the enumerator collection value. First you map the collection value to a user-defined variable, and then you implement a property expression on the property that uses the variable. For example, the collection value of the Foreach File enumerator is mapped to a variable called MyFile and the variable is then used in the property expression for the Subject property of a Send Mail task. When the package runs, the Subject property is updated with the name of a file each time that the loop repeats. For more information, see Using Property Expressions in Packages.
Variables that are mapped to the enumerator collection value can also be used in expressions and scripts.
A Foreach Loop container can include multiple tasks and containers, but it can use only one type of enumerator. If the Foreach Loop container includes multiple tasks, you can map the enumerator collection value to multiple properties of each task.

1 comment:

  1. Thank U For Giving The Great Information………..We Are Providing SAP Online Training
    " http://www.sapramsonlinetraining.com/msbi-online-training/
    ">MSBI Online Training , At Your Convenience By IT Professionals , Sapramsonlinetraining is a leading online training provider across the globe. Register Free Demo now.

    ReplyDelete