How to concatenate 2 files in SSIS (Integration Services)?

折月煮酒 提交于 2019-12-24 05:12:38

问题


I have 2 files that do not have the same columns. I want to be able to concatenate them, but I can't seem to find a way to do this. I thought about using a Script Component, but that still wants you to declare output columns.

The first file has columns and data like this:

A|B|C|D|E|F|G
Adata1|Bdata1|Cdata1|Ddata1|Edata1|Fdata1|Gdata1
Adata2|Bdata2|Cdata2|Ddata2|Edata2|Fdata2|Gdata2
Adata3|Bdata3|Cdata3|Ddata3|Edata3|Fdata3|Gdata3
Adata4|Bdata4|Cdata4|Ddata4|Edata4|Fdata4|Gdata4

The second file has columns and data like this:

H|I|J|K|L|M|N
Hdata1|Idata1|Jdata1|Kdata1|Ldata1|Mdata1|Ndata1
Hdata2|Idata2|Jdata2|Kdata2|Ldata2|Mdata2|Ndata2
Hdata3|Idata3|Jdata3|Kdata3|Ldata3|Mdata3|Ndata3
Hdata4|Idata4|Jdata4|Kdata4|Ldata4|Mdata4|Ndata4

I need the overall output file to look like this:

A|B|C|D|E|F|G
Adata1|Bdata1|Cdata1|Ddata1|Edata1|Fdata1|Gdata1
Adata2|Bdata2|Cdata2|Ddata2|Edata2|Fdata2|Gdata2
Adata3|Bdata3|Cdata3|Ddata3|Edata3|Fdata3|Gdata3
Adata4|Bdata4|Cdata4|Ddata4|Edata4|Fdata4|Gdata4
H|I|J|K|L|M|N
Hdata1|Idata1|Jdata1|Kdata1|Ldata1|Mdata1|Ndata1
Hdata2|Idata2|Jdata2|Kdata2|Ldata2|Mdata2|Ndata2
Hdata3|Idata3|Jdata3|Kdata3|Ldata3|Mdata3|Ndata3
Hdata4|Idata4|Jdata4|Kdata4|Ldata4|Mdata4|Ndata4

I know it's out of the ordinary, but that's the requirements...

Any suggestions?


回答1:


Go with a script task. If you have connection managers for your 3 files, you don't need any inputs to the task.

Access the connection strings with:

var fileAString = Dts.Connections["fileAConnectionManagerName"].ConnectionString;

Workflow can be, open fileC for write. Open fileA for read. Read data and write to fileC. Close fileA. Open fileB for read. Read data and write to fileC. Close files and return success.



来源:https://stackoverflow.com/questions/32384173/how-to-concatenate-2-files-in-ssis-integration-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!