需要导入具有不同部分的平面文件,其中包含不同的列 [英] Need to import a flat file with different section with different columns in it

查看:113
本文介绍了需要导入具有不同部分的平面文件,其中包含不同的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'|'分隔的Flat文件,在3个不同的部分中有不同的列。



每个部分由第二列中的值标识。



我必须阅读此文件并通过SSIS将其加载到表中。



这将是如果有人为它提供解决方案,那就更好了。



请找到下面提到的样本数据



样本数据:

UPD | 1 | 123 | 20180502 | JOHN | 20180502

UPD | 1 | 345 | 20180502 |彼得| 20180502

UPD | 2 | 456 | 20180502 | X | A

UPD | 2 | 912 | 20180502 | Y | A

UPD | 3 | | 257 | 20180502 | X | A

UPD | 3 | | 756 | 20180502 | Y | A





如果您注意到第3部分有一个额外的列。仅在第3节中我们就有7列,但在剩下的部分我们只有6列。



我需要这样的输出:



UPD 1 123 20180502 JOHN 20180502

UPD 1 345 20180502 PETER 20180502

UPD 2 456 20180502 XA

UPD 2 912 20180502 YA

UPD 3 257 20180502 XA

UPD 3 756 20180502 YA



我尝试了什么:



如果我通过ssis中的file_file_source读取此文件,数据就是这样,平面文件只考虑6列和第3列,第7列值显示在第6列本身。



UPD 1 123 20180502 JOHN 20180502

UPD 1 345 20180502 PETER 20180502

UPD 2 456 20180502 XA

UPD 2 912 20180502 YA

UPD 3 257 20180502 X | A
UPD 3 756 20180502 Y | A



对于第3部分,最后一列的值显示为X | A。



任何帮助将不胜感激。在此先感谢。



问候,

Gopinath

I have a '|' delimited Flat file with varying columns in 3 different sections.

Each section is identified by the value in the second column.

I have to read this file and load it in a table through SSIS.

It would be better if someone provides a solution for it.

Please find the below mentioned sample data

Sample data:
UPD|1|123|20180502|JOHN|20180502
UPD|1|345|20180502|PETER|20180502
UPD|2|456|20180502|X|A
UPD|2|912|20180502|Y|A
UPD|3| |257|20180502|X|A
UPD|3| |756|20180502|Y|A


If you notice the 3rd section has got an extra column. In section 3 alone we have got 7 columns but in rest of the section we have only 6 columns.

I need a output like this:

UPD 1 123 20180502 JOHN 20180502
UPD 1 345 20180502 PETER 20180502
UPD 2 456 20180502 X A
UPD 2 912 20180502 Y A
UPD 3 257 20180502 X A
UPD 3 756 20180502 Y A

What I have tried:

If i read this file through file_file_source in ssis the data is coming like this, the flat file is considering only the 6 columns and for the section 3, 7th column value is displayed in 6th column itself.

UPD 1 123 20180502 JOHN 20180502
UPD 1 345 20180502 PETER 20180502
UPD 2 456 20180502 X A
UPD 2 912 20180502 Y A
UPD 3 257 20180502 X|A
UPD 3 756 20180502 Y|A

For section 3 the last column value is displayed as "X|A".

Any help would be greatly appreciated. Thanks in advance.

Regards,
Gopinath

推荐答案

你好Gopinath,



这是一个老问题,所以你可能已经在其他地方找到了答案。如果没有,请查看我关于动态列映射的文章: SSIS中的动态文件列映射。 - SQLServerCentral [ ^ ]



我的解决方案处理平面文件中的变量列,其中所有行的值与文件中的列数相同。但是,在我的解决方案中使用的脚本组件中,很容易实现代码更改,以便在读取数据时处理行与行之间的任何差异。



此致,



Hiske
Hi there Gopinath,

It's an old question, so you might have already found an answer elsewhere. If not, take a look at my article on dynamic column mapping: Dynamic File Column mapping in SSIS. - SQLServerCentral[^]

My solution deals with variable columns in flat files where all rows have the same number of values as there are columns in the file. However, in the Script Component used in my solution, it's easy to implement code changes to handle any differences from row-to-row as the data is being read.

Regards,

Hiske


这篇关于需要导入具有不同部分的平面文件,其中包含不同的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆