创建 SSIS 包以从多个数据源之一导入
是否可以创建一个可以传递文件(通过变量)并从变量确定要使用哪个数据流任务的 SSIS 包?
我希望能够做的是创建一个 DTSX 包,它可以将文件名作为变量并检测(只需从文件名)它是否是 Excel 2003、Excel 2007 或 CSV 文件,然后执行正确的数据流任务。导入数据后,我将在另一个数据流任务中处理结果。
我很久以前就用过SSIS,现在我才重新开始使用它,所以我的知识被锁起来了,会慢慢回来的。我只是似乎不记得(或在谷歌上找到)一种在控制流中创建条件分割的方法。
有什么想法吗?
Is it possible to create an SSIS package that can be passed a file (through a variable) and from the variable determine which Data Flow Task to use?
What I would like to be able to do is to create a single DTSX package that can take in a filename as a variable and detect (simply from the filename) if it is an Excel 2003, Excel 2007 or CSV file and from that, execute the correct Data Flow Task. I will then process the results in another single Data Flow Task after the data has been imported.
I used SSIS a long time ago and I am just coming back to using it so my knowledge is locked away and will come back slowly. I just can't seem to remember (or find on Google) a way of creating a conditional split in the Control Flow.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 HLGEM 所指出的,只要内部结构一致,这样就足够了。
我声明了一个包级变量
DatFlowSelector
,并且在我的初始脚本任务中,我将使用逻辑来根据您的FileName
变量确定流应采用的路径正要使用。连接预期输出后,使用优先约束编辑器确定哪条路径计算结果为 true。我的逻辑很简单
@[User::DataFlowSelector] == N
其中 N 映射到我的脚本分配的值。当我修改约束时,我通常将
ShowAnnotation
属性切换为“ConstraintOptions”,因为它可以让未来的维护者立即清楚地知道发生了什么事。 SQL 2012 在这种情况下会有所帮助,因为它会将fx
字形分配给连接器,但显示逻辑可以提供对合理逻辑的一目了然的确认。As HLGEM has indicated, as long as the internal structure was consistent, something like this would suffice.
I'd declared a package level variable,
DatFlowSelector
and within my initial script task, I'd use logic to determine what path the flow should take based on theFileName
variable you were going to use.After wiring up the expected outputs, use the Precedence Constraint editor to determine what path evaluates to true. My logic was simply
@[User::DataFlowSelector] == N
where N maps to the value my script assigned.I generally switch the
ShowAnnotation
property to "ConstraintOptions" when I modify the constraints as it makes it immediately clear to future maintainers that there is something going on. SQL 2012 will help in this case as it assigns thefx
glyph to the connector but displaying the logic can provide at-a-glance confirmation of sound logic.我在控制流中对每个循环做了类似的事情。它遍历处理目录中的所有文件,并根据文件名将它们定向到正确的数据流(因为它们都是相同的文件类型,但具有不同的内部结构)。
I did something similar with a for each loop in the control flow. It went through all the files in the processing directory and directed them to the correct dataflow based on the name of the file (since they were all the same file type but with different internal structures).