Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a text file with SSIS with CRLF or LF

Tags:

sql

ssis

Running into an issue where I receive a text file that has LF's as the EOL. Sometimes they send the file with CRLF's as the EOL. Does anyone have any good ideas on how I can make SSIS use either one as the EOL?

It's a very easy convert operation with notepad++ to change it to what ever I need, however, it's manual and I want it to be automatic.

Thanks,

EDIT. I fixed it (but not perfect) by using Swiss File Knife before the dataflow.

like image 610
Dayton Brown Avatar asked May 24 '12 15:05

Dayton Brown


People also ask

What is CR and LF in SSIS?

{CR} The header row is delimited by a carriage return. {LF} The header row is delimited by a line feed.

How do I add special characters in SSIS?

Basically you need to read the file using Codepage 65001 (UTF-8), then use Derived Column transformation where you would add a derived column for every text field in the csv file using cast expressions, for example (DT_STR,50,1252)LastName.


2 Answers

If the line terminators are always one or the other, I'd suggest setting up 2 File Connection Managers, one with the "CRLF" row delimiter, and the other with the "LF" row delimiter.

Then, create a boolean package variable (something like @IsCrLf) and scope this to your package. Make the first step in your SSIS package a Script Task, in which you read in a file stream, and attempt to discover what the line terminator is (based on what you find in the stream). Set the value of your variable accordingly.

Then, after the Script Task in your Control Flow, create 2 separate Data Flows (one for each File Connection Manager) and use a Precedence Constraint set to "Expression and Constraint" on the connectors to specify which Data Flow to use, depending on the value of the @IsCrLf variable.

Example of the suggested Control Flow below.

Example SSIS Control Flow

like image 105
GShenanigan Avatar answered Oct 08 '22 16:10

GShenanigan


how about a derived column with the REPLACE operation after your file source to change the CRLFs to LFs?

like image 30
Diego Avatar answered Oct 08 '22 15:10

Diego