I want to import a CSV file to Database table using SSIS package. Problem is the CSV file does not have trailing commas if the cell value is blank/null.

Example of CSV file:

Id,City,State,Zip
1,NYC,New York,12345
2,LONDON
3,PARIS
4,LA,California,67890

Ideally it should have been:

2,LONDON,,
3,PARIS,,

SSIS Flat file connection only checks {CR}{LF} on the last column. Does anyone know any workaround to import this data using SSIS (i.e. without manual workaround)?

Thanks.

有帮助吗?

解决方案

My personal choice would be to do what Bill suggested in his comment. Pre-process the input file with a script task, which will add any missing commas to act as placeholders for your Flat File Source.

There are scenarios where this is not possible however. In such a case you could use the Script Component tool in your data flow task set up as a Source. A very good approach to what needs to be in that script can be found here:

http://beyondrelational.com/modules/2/blogs/106/posts/11128/ssis-script-component-add-missing-column-or-ignore-extra-columns.aspx

This method is very flexible as it would deal with rows that have less number of columns coming in, as well as the cases where more columns might appear.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top