Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Use the Collection pageof the Foreach Loop Editor dialog box to specify the enumerator type and configure the enumerator.
Select the enumerator type from the list. This property has the options listed in the following table.
Foreach File Enumerator
Enumerate files. Selecting this value displays the dynamic options in the section, Foreach File Enumerator.
Foreach Item Enumerator
Enumerate values in an item. Selecting this value displays the dynamic options in the section, Foreach Item Enumerator.
Foreach ADO Enumerator
Enumerate tables or rows in tables. Selecting this value displays the dynamic options in the section, Foreach ADO Enumerator.
Foreach ADO.NET Schema Rowset Enumerator
Enumerate a schema. Selecting this value displays the dynamic options in the section, Foreach ADO.NET Enumerator.
Foreach From Variable Enumerator
Enumerate the value in a variable. Selecting this value displays the dynamic options in the section, Foreach From Variable Enumerator.
Foreach Nodelist Enumerator
Enumerate nodes in an XML document. Selecting this value displays the dynamic options in the section, Foreach Nodelist Enumerator.
Foreach SMO Enumerator
Enumerate a SMO object. Selecting this value displays the dynamic options in the section, Foreach SMO Enumerator.
Click or expand Expressions to view the list of existing property expressions. Click the ellipsis button (…) to add a property expression for an enumerator property, or edit and evaluate an existing property expression.
You use the Foreach File enumerator to enumerate files in a folder. For example, if the Foreach Loop includes an Execute SQL task, you can use the Foreach File enumerator to enumerate files that contain SQL statements that the Execute SQL task runs. The enumerator can be configured to include subfolders.
The content of the folders and subfolders that the Foreach File enumerator enumerates might change while the loop is executing because external processes or tasks in the loop add, rename, or delete files while the loop is executing. This means that a number of unexpected situations may occur:
If files are deleted, one task in the Foreach Loop may perform work on a different set of files than the files used by subsequent tasks.
If files are renamed and an external process automatically adds files to replace the renamed files, the Foreach Loop might perform work twice on the same file content.
If files are added, it may be difficult to determine for which files the Foreach Loop performed work.
Provide the path of the root folder to enumerate.
Browse to locate the root folder.
Specify the files to enumerate.
Use wildcard characters (*) to specify the files to include in the collection. For example, to include files with names that contain “abc”, use the following filter: *abc*.
When you specify a file name extension, the enumerator also returns files that have the same extension with additional characters appended. (This is the same behavior as that of the dir command in the operating system, which also compares 8.3 file names for backward compatibility.) This behavior of the enumerator could cause unexpected results. For example, you want to enumerate only Excel 2003 files, and you specify "*.xls". However, the enumerator will also return Excel 2007 files because those files have the extension, ".xlsx".
You can use an expression to specify the files to include in a collection, by expanding Expressions on the Collection page, selecting the FileSpec property, and then clicking the ellipsis button (…) to add the property expression. For more information about dynamically selecting specified files, see SSIS–Dynamically set File Mask : FileSpec
Select to retrieve the fully qualified path of file names. If wildcard characters are specified in the Files option, then the fully-qualified paths that are returned match the filter.
Select to retrieve only the file names. If wildcard characters are specified in the Files option, then the file names returned match the filter.
Name and extension
Select to retrieve the file names and their file name extensions. If wildcard characters are specified in the Files option, then the name and extension of files returned match the filter.
Select to include the subfolders in the enumeration.
Enumerator = Foreach Item Enumerator
You use the Foreach Item enumerator to enumerate items in a collection. You define the items in the collection by specifying columns and column values. The columns in a row define an item. For example, an item that specifies the executables that an Execute Process task runs and the working directory that the task uses has two columns, one that lists the names of executables and one that lists the working directory. The number of rows determines the number of times that the loop is repeated. If the table has 10 rows, the loop repeats 10 times.
To update the properties of the Execute Process task, you map variables to item columns by using the index of the column. The first column defined in the enumerator item has the index value 0, the second column 1, and so on. The variable values are updated with each repeat of the loop. The Executable and WorkingDirectory properties of the Execute Process task can then be updated by property expressions that use these variables.
Define the items in the For Each Item collection
Provide a value for each column in the table.
A new row is automatically added to the table after you enter values in row columns.
If the values provided are not compatible with the column data type, the text is colored red.
Column data type
Lists the data type of the active column.
Select an item, and then click Remove to remove it from the list.
Click to configure the data type of the columns in the item.
You use the Foreach ADO enumerator to enumerate rows or tables in an ADO or ADO.NET object that is stored in a variable. For example, if the Foreach Loop includes a Script task that writes a dataset to a variable, you can use the Foreach ADO enumerator to enumerate the rows in the dataset. If the variable contains an ADO.NET dataset, the enumerator can be configured to enumerate rows in multiple tables or to enumerate tables.
ADO object source variable
Select a user-defined variable in the list, or click <New variable...> to create a new variable.
The variable must have the Object data type, otherwise an error occurs.
You use the Foreach ADO.NET Schema Rowset enumerator to enumerate a schema for a specified data source. For example, if the Foreach Loop includes an Execute SQL task, you can use the Foreach ADO.NET Schema Rowset enumerator to enumerate schemas such as the columns in the AdventureWorks database, and the Execute SQL task to get the schema permissions.
Select an ADO.NET connection manager in the list, or click <New connection...> to create a new ADO.NET connection manager.
The ADO.NET connection manager must use a .NET provider for OLE DB. If connecting to SQL Server, the recommended provider to use is the SQL Server Native Client, listed in the .Net Providers for OleDb section of the Connection Manager dialog box.
You use the Foreach From Variable enumerator to enumerate the enumerable objects in the specified variable. For example, if the Foreach Loop includes an Execute SQL task that runs a query and stores the result in a variable, you can use the Foreach From Variable enumerator to enumerate the query results.
Select a variable in the list, or click <New variable...> to create a new variable.
You use the Foreach Nodelist enumerator to enumerate the set of XML nodes that results from applying an XPath expression to an XML file. For example, if the Foreach Loop includes a Script task, you can use the Foreach NodeList enumerator to pass a value that meets the XPath expression criteria from the XML file to the Script task.
The XPath expression that applies to the XML file is the outer XPath operation, stored in the OuterXPathString property. If the XPath enumeration type is set to ElementCollection, the Foreach NodeList enumerator can apply an inner XPath expression, stored in the InnerXPathString property, to a collection of element.
You use the Foreach SMO enumerator to enumerate SQL Server Management Object (SMO) objects. For example, if the Foreach Loop includes an Execute SQL task, you can use the Foreach SMO enumerator to enumerate the tables in the AdventureWorks database and run queries that counts the number of rows in each table.
Select an existing ADO.NET connection manager, or click <New connection...> to create a new connection manager.