This SSIS Integration Services article shows how to export SQL Server table data or records to a Ragged Right fixed width flat file.
The below screenshot shows the rows in the Employee table.
SSIS Export SQL Data to Ragged Right Fixed Width Flat File
Drag the SSIS Data Flow Task into the control flow region.
Double-click to open the Data Flow Region. Then, drag the OLE DB Source and double-click on it to open the Editor. Next, click the New button to configure the OLE DB Connection Manager. Here, we have chosen the existing one, but you can create a fresh one by clicking the New button (arrow pointed).
We choose the Employee table from the list of available ones. Next, go to the columns tab to check the columns and click the Ok button.
Drag the flat file destination and connect the OLE DB source to it. Next, Double-click on the flat file destination to open the Editor, and click on the new button to choose the Fixed Width as the flat file format.
Click the Browse button to create a new file to store the Ragged Right Fixed Width records.
Next, checkmark the Column Names in the first data row option to copy the headers.
Within the Advanced tab, change the InputColumnWidth value to adjust the row items. For instance, EmpID = 10, Names = 50, etc.
To find the exact value,
- Check the maximum length of each column and add that value to it.
- Then, go to SQL Management Studio and type the following query.
- Remember to replace the FirstName with your SQL columns.
SELECT MAX(LEN(FirstName)) InputColumnWidth
Change the InputColumnWidth value for the remaining columns. After you finish, click OK to close the window.
Within the Flat File Destination Editor, go to the Mappings tab to check the input and available destination column mapping.
Run the SSIS Export SQL Data to Ragged Right Fixed Width Flat File package.
As you can see, the text file has all the records where a Ragged Right Fixed Width of space separates each column.