Sql-server – Line-breaks in Text column of CSV file

bulk-insertcsvimportsql server

I have come across an awkward situation where I have got CSV files with | as the column delimiter. In these files, I don't have Text column qualifier. (i.e. ").
My problem is when I am importing these CSV files using BULK INSERT, if the last column of a row has a line break in it, the text continues into the next row.
I am unable to use SSIS so I am looking for a pure T-SQL solution.

It would be great if someone could guide me in the right direction. I tried reading files using openrowset but that's not changing anything either.

Best Answer

This is probably due to the fact that the text has Carriage Returns in it and that you are using the default row delimiter which is the Carriage Return.

This will be tough to fix since you can't know when a Carriage Return is part of a column or actually a new line. the file needs to be fixed manually.

Unless you know where the file came from... If there's a possibility for you to reprocess the file, then I would reprocess it, replacing all Carriage Returns found in columns by blanks ('').

I hope this helps.