Can SSIS support loading of files with varying column lengths in each row?

落爺英雄遲暮 提交于 2019-12-24 02:15:57

问题


Currently I receive a daily file of around 750k rows and each row has a 3 character identifier at the start.

For each identifier, the number of columns can change but are specific to the identifier (e.g. SRH will always have 6 columns, AAA will always have 10 and so on).

I would like to be able to automate this file into an SQL table through SSIS.

This solution is currently built in MSACCESS using VBA just looping through recordsets using a CASE statement, it then writes a record to the relevant table.

I have been reading up on BULK INSERT, BCP (w/Format File) and Conditional Split in SSIS however I always seem to get stuck at the first hurdle of even loading the file in as SSIS errors due to variable column layouts.

The data file is pipe delimited and looks similar to the below.

AAA|20180910|POOL|OPER|X|C
SRH|TRANS|TAB|BARKING|FORM|C|1.026
BHP|1
*BPI|10|16|18|Z
BHP|2
*BPI|18|21|24|A

(* I have added the * to show that these are child records of the parent record, in this case BHP can have multiple BPI records underneath it)

I would like to be able to load the TXT file into a staging table, and then I can write the TSQL to loop through the records and parse them to their relevant tables (AAA - tblAAA, SRH - tblSRH...)


回答1:


I think you should read each row as one column of type DT_WSTR and length = 4000 then you need to implement the same logic written using vba within a Script component (VB.NET / C#), there are similar posts that can give you some insights:

  • SSIS ragged file not recognized CRLF
  • SSIS reading LF as terminator when its set as CRLF
  • How to load mixed record type fixed width file? And also file contain two header
  • SSIS Flat File - CSV formatting not working for multi-line fileds
  • how to skip a bad row in ssis flat file source


来源:https://stackoverflow.com/questions/56942190/can-ssis-support-loading-of-files-with-varying-column-lengths-in-each-row

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