SSIS Flat File Export - "Fixed Width" vs "Ragged Right"
Back in the late 90s, I worked on a number of projects where we had to generate fixed width flat files to send to external systems -- we would use the SQL Server DTS wizard to generate them, and everything worked fine.
I recently needed to generate fixed width flat files from SQL Server 2005, so I ran SSIS and everything looks pretty much the same as DTS -- except when choosing "Fixed Width" as the export option, the entire flat file was generated with no linefeeds/carriage returns in it.
It turns out there is another option, "Ragged Right", which is exactly the same as "Fixed Width", except that it gives you the option to insert a linefeed character (or CRLF, etc.) at the end of each line of data.
Here's a quick walkthrough for generating fixed width flat files with line breaks from SSIS. For this example, I'm assuming that we'll be selecting data "as-is" from a staging table that is already set up with the correct column widths and contains data exactly as it should be in the fixed width file.
1) In SQL Server Management Studio, right click on the database containing the table or data you want to export, and select "Tasks/Export Data..."
2) For the data source, you can leave the default settings.
3) For the target, select "Flat File Destination" as the Destination, pick a file name, and under "Format", select "Ragged right"
4) Click through the next dialog, which gives you the option to specify a query or just select straight from a table. We're going to select from a table here. On the "Configure Flat File Destination" screen, pick the table you want to export, and choose the row delimiter. The default is "CRLF", which is generally good for windows, but if you are sending the file to be processed on another OS or for a specific app, you may need to choose a different linefeed character or sequence.
That's it! Execute the package or save it off, and you should have a fixed width flat file with linefeeds.