Foreach Loop container in SSIS allows you to loop over the values of the
object variable and store the necessary information as a result set to
variables to be used anywhere in SSIS for different purposes.
1- Create a object variable and fill it with information:
See: SSIS – Storing Dataflow results to Object Variable with Recordset Destination
See: SSIS – Mapping Full Resultset with Execute SQL Task to Object Variable
(Both examples above fill Object variable with sys.tables data within the msdb database in SQL server.)
2- Create two more variables to hold the table name (string) and object id (integer)
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/350x0/__key/communityserver-wikis-components-files/00-00-00-00-05/8228.ScreenShot141.jpg)
3- Drag&Drop a Foreach Loop container to Dataflow:
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/350x0/__key/communityserver-wikis-components-files/00-00-00-00-05/2538.ScreenShot143.jpg)
4- Go Collection tab and Select “Foreach ADO Enumerator” for Enumeration
and select your ObjVariable as “ADO Object Source Variable” and specify
“Enumeration Mode” as “Rows in the First Table”
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/550x0/__key/communityserver-wikis-components-files/00-00-00-00-05/8468.ScreenShot144.jpg)
5- Go to Variable Mappings Tab and add your map your variables to relevant index of your data in the Object Variable
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/550x0/__key/communityserver-wikis-components-files/00-00-00-00-05/8883.ScreenShot145.jpg)
Variable index is zero based and must be index of the column in the
dataset. We use Tablename and objectId which indexes are 0,1 in order.
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/450x0/__key/communityserver-wikis-components-files/00-00-00-00-05/4657.ScreenShot142.jpg)
6- Drag&Drop Script Component to see the values mapped and run the package.
![](http://social.technet.microsoft.com/wiki/resized-image.ashx/__size/450x0/__key/communityserver-wikis-components-files/00-00-00-00-05/3582.ScreenShot147.jpg)