更新时间:2022-11-03 07:39:22
您可以在foreach循环中使用一个DataFlow Task来实现此目的,但诀窍是您必须从变量读取源平面文件名和Destination SQL表名
You can achieving this using one DataFlow Task inside the foreach loop, but the trick is that you have to Read source flat file name and the Destination SQL Table name from variables
注意:平面文件结构必须相同,并且SQL表必须具有相同的结构
Control Flow
窗口,然后单击Variables
Control Flow
window and click on Variables
声明2个SSIS变量:
Declare 2 SSIS variables:
FlatFilename
:类型为String
,并为默认值分配一个随机文件路径(即C:\MockFolder\FileA.txt
) : of type
String`并分配给以下表达式:FlatFilename
: of type String
and assign a default value a random file path (i.e. C:\MockFolder\FileA.txt
)
: of type
String` and assign to the following expression: 这是假定所有目标表都具有相同的架构dbo
"[dbo].[" + REPLACE(RIGHT( @[User::FlatFilename] , FINDSTRING(REVERSE( @[User::FlatFilename] ) , "\\", 1) - 1),".txt","") + "]"
Foreach Loop Container
和DataFlow Task
,单击DataFlow Task
,然后在属性选项卡上,将Delay Validation
属性设置为True
Foreach Loop Container
and a DataFlow Task
inside it, click on the DataFlow Task
and on the properties Tab, Set the Delay Validation
property to True
Foreach Loop container
并选择主目录,然后文件过滤器*.txt
也选择fully qualified
检索文件名选项Foreach Loop container
and select the main Directory , and the files filter *.txt
also choose the fully qualified
retrieve file name option
@[User::FlatFilename]
变量
添加2个连接管理器
Add 2 Connection manager
File
(即C:\MockFolder\FileA.txt
) File
(i.e. C:\MockFolder\FileA.txt
)
在DataFlow Task
中,添加Flat File Source
和OLEDB Destination
,在OLEDB Destination
中选择Table name from variable
选项,然后选择@[User::SQLTablename]
作为变量名
In The DataFlow Task
, add a Flat File Source
and an OLEDB Destination
, in the OLEDB Destination
select Table name from variable
option and select @[User::SQLTablename]
as the variable name
在源和目标之间映射列
Map columns between source and Destination
在连接管理器窗口中单击FlatFileConnection
,按F4
以显示属性选项卡,单击表达式"
Click on the FlatFileConnection
in the connection manager windows, press F4
to show the properties Tab, click on Expressions
选择Connection String
属性,为其分配以下表达式:
Select the Connection String
property assign to it the following expression:
@[user::FlatFilename]