Importing Text Files with Similar Schemas and File Names from Different Directories
Importing multiple text files with identical names and schemas into a single table in SQL Server 2008 can be achieved using SSIS.
Using a Foreach File Container with Subfolder Traverse
Setting the ConnectionString Dynamically
Within each loop of the Foreach File Container:
Data Import Configuration
Example Walkthrough
Here's an example package that demonstrates this approach:
Create a For Each File Loop task:
Set the Directory property to the root of the file hierarchy (C:ssisdatasoTEST).
Enable Process Subfolders.
Set the FileSpec property to a wildcard filter (*.txt).
Within the For Each File Loop task, create a Data Flow task:
Add a Flat File Source component and connect it to the Flat File Connection Manager.
Set an Expression on the Flat File Source's ConnectionString property to use the @[User::CurrentFileName] variable.
Add a RowCount component to count the rows processed from the file.
Add an OLE DB Destination component to load the data into the database table.
The above is the detailed content of How Can I Import Multiple Text Files with Identical Schemas and Names from Different Directories into SQL Server 2008 Using SSIS?. For more information, please follow other related articles on the PHP Chinese website!