Note: |
---|
To avoid validation errors when you configure the File connection managers, CreateTableSQL and SelectCountSQL, existing files have already been selected in the File Connection Manager Editor. |
Important: |
---|
Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples. |
File | Description |
---|---|
ExecuteSQLStatementsInLoop.dtsx | The package file. |
Customer.txt | The source data file. |
CustomersWithInvalidTerritoryID.txt | The file to which data that is not valid is written. |
CreateProspectTableTerr1.sql | The Transact-SQL statement that creates the Territory1 table. |
CreateProspectTableTerr2.sql | The Transact-SQL statement that creates the Territory2 table. |
CreateProspectTableTerr3.sql | The Transact-SQL statement that creates the Territory3 table. |
CreateProspectTableTerr4.sql | The Transact-SQL statement that creates the Territory4 table. |
CreateProspectTableTerr5.sql | The Transact-SQL statement that creates the Territory5 table. |
Select ProspectTableTerr1.sql | The Transact-SQL statement that returns the row count for Territory1 table. |
Select ProspectTableTerr2.sql | The Transact-SQL statement that returns the row count for Territory2 table. |
Select ProspectTableTerr3.sql | The Transact-SQL statement that returns the row count for Territory3 table. |
Select ProspectTableTerr4.sql | The Transact-SQL statement that returns the row count for Territory4 table. |
Select ProspectTableTerr5.sql | The Transact-SQL statement that returns the row count for Territory5 table. |
Important: |
---|
If you open the Execute SQL Statements in a Loop sample package in SSIS Designer before you run the package for the first time, the Data Flow task includes a warning. The warning occurs because the SQL Server tables that the package uses do not exist yet; the tables are created the first time that you run the package. The warning does not appear when you reopen the package in SSIS Designer, if you have run the package at least one time. The package runs successfully regardless of the warning. |
Element | Purpose |
---|---|
Foreach Loop | The Foreach Loop container, Run SQL Statements, uses the Foreach File enumerator to iterate through files that contain Transact-SQL statements. The Foreach Loop container includes an Execute SQL task. |
Execute SQL task | The Execute SQL task, Create Tables, connects to the AdventureWorks database. The task then uses the File connection manager, CreateTableSQL, to access the files that contain the Transact-SQL statements that create the tables. Finally, the task runs the Transact-SQL statements and creates the tables in the database. |
Data Flow task | The Data Flow task, Extract-Clean-Load Data, executes a data flow that extracts the data from a text file, cleans and distributes the data, and then loads the data into tables in the AdventureWorks database. |
Flat File source | The Flat File source, Extract data, extracts the data from the text file. |
Conditional Split transformation | The Conditional Split transformation, Direct Rows by TerritoryID, directs rows to different outputs depending on the value in the TerritoryID column. Rows with invalid values in TerritoryID are directed to the default output. |
Derived Column transformation | The Derived Column transformation, Fix Postal Code, cleans the postal codes by adding a leading zero to four-character postal codes. |
OLE DB Destination | Five OLE DB destinations load data into five different territory tables. |
Foreach Loop container | The Foreach Loop container, Run SQL Select Statements, uses the Foreach File enumerator to iterate through files that contain the Transact-SQL statements that returns the row count for each table. The container has an Execute SQL task, Select Table Count, and a Script task, Display Table Count. |
Execute SQL task | The Execute SQL task, Select Table Count, connects to the AdventureWorks database. The task then uses the File connection manager, SelectCountSQL, to access the files that contain the Transact-SQL statements that return the row count for each table. The task runs the Transact-SQL statements and stores the row count, as a Single row result set, in a package variable. |
Script task | The Script task, Display Table Count, displays the row count for each of the five tables. |
File connection manager | The File connection manager, SelectCountSQL, connects to files that contain SQL SELECT COUNT statements. |
File connection manager | The File connection manager, CreateTableSQL, connects to files that contain SQL CREATE TABLE statements. |
Flat File connection managers | The File connection manager, Customers, connects to the text file that contains the customer source data.The File connection manager, CustomsWithInvalidTerritoryId, connects to the text file to which the package writes invalid data. |
OLE DB connection manager | The OLE DB connection manager, (local).AdventureWorks, connects to the AdventureWorks database on the local server. |
SELECT * FROM AdventureWorks.dbo.Territory1 SELECT * FROM AdventureWorks.dbo.Territory2 SELECT * FROM AdventureWorks.dbo.Territory3 SELECT * FROM AdventureWorks.dbo.Territory4 SELECT * FROM AdventureWorks.dbo.Territory5 | This query retrieves the data that was extracted from the text file and loaded into SQL Server tables. © 2008 Microsoft Corporation. All rights reserved. |