How to write data into CSV file in SSIS (GZip / Split)

Introduction

ssis-csv-file-destinationIn this article, we will see how to read How to write data into CSV file in SSIS from SQL Server. We will also explain how to compress (gzip) and split  CSV files into multiple files. To illustrate, we will use ZappySys SSIS PowerPack, which includes several tasks to import/export data from multiples sources to multiple destinations like flat files, Azure, AWS, databases, Office files and more. They are Coding free, drag and drop high-performance suite of Custom SSIS Components and SSIS Tasks. We will use the ZS CSV File Destination component for this article.

 

What is CSV File Destination?

CSV File Destination can be used to write data in CSV / TSV file format. You can also split large files by row count or size at runtime. It also supports writing files directly in a compressed format such as GZip (*.gz).

Prerequisites

Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:

  1. SSIS designer installed. Sometimes it is referred to as BIDS or SSDT (download it from Microsoft site).
  2. Basic knowledge of SSIS package development using Microsoft SQL Server Integration Services.
  3. Make sure ZappySys SSIS PowerPack is installed (download it).

Component Mentioned in this article

How to Extract Data from SQL Server Table to CSV File Destination.

In this tutorial, we are going to load data from SQL Server Table using OLE DB Source and ZS CSV File Destination. You can use ZS DummyData Source too for practice it.

  1. Firstly, you need to Download and Install SSIS ZappySys PowerPack.
  2. Once you finished the first step, Open Visual Studio and Create New SSIS Package Project.
  3. Now, Drag and Drop SSIS Data Flow Task from SSIS Toolbox.
    Drag and Drop SSIS Data Flow Task from SSIS Toolbox

    Drag and Drop SSIS Data Flow Task from SSIS Toolbox

  4. Double click on the Data Flow task to see the Data Flow designer surface.
  5. Here, In Visual Studio, drag and drop the OLE DB Source and CSV File Destination in the design surface and join the tasks with the blue arrow.
    SSIS OLE DB Source and CSV File Destination - Drag and Drop

    SSIS OLE DB Source and CSV File Destination – Drag and Drop

  6. Here, you can use our ZS Data Source too.
  7. But, we are going through OLE DB Source so need OLE DB Connection and File Connection for CSV File Destination.

How to create OLE DB Connection.

  1. Lets, create the first OLE DB Connection.
  2. Let’s, Right-click on Connection Managers Panel to Create OLE DB Connection, so you can use Source and Context Menu will appear, Select New OLE DB Connection from the Context Menu.
    Create OLE DB Connection

    Create OLE DB Connection

  3. Now, click on New Button to create Connection.
    Create New OLE DB Connection

    Create New OLE DB Connection

  4. Let’s Configure Connection Manager, just Follow steps one by one as we have created.
    Configure OLE DB Connection Manager

    Configure OLE DB Connection Manager

  5. Click on Test Connection to see correct configure it.
  6. Click on OK button to save connection configure setting UI.

How to Create a File Connection.

  1. Let’s, Right-click on Connection Managers Panel to Create File Connection, so you can use Destination Path, and Context Menu will appear, Select New Connection from the Context Menu. In the File Connection Manager, select the Usage type and specify the path of the CSV file.
    CSV File: You can download good one CSV file from here for practice.
    Create a New File Connection

    Create a New File Connection

  2. Click on OK button to save connection configure setting UI.

Let’s see how to write data from SQL Server Table to CSV File.

  1. Double click on OLE DB Source for configure it.
  2. Let’s Configure in Connection Manager, just follow below image steps.
    Configure OLE DB Source Editor

    Configure OLE DB Source Editor

  3. Click OK to Save OLE DB Source Editor UI Settings.
  4. Let’s configure CSV File Destination, Double click on it, In the File Connection Manager, select the file connection created before.
    SSIS ZS CSV File Destination - Configure Connection Manager Tab

    SSIS ZS CSV File Destination – Configure Connection Manager Tab

  5. In the Component Properties, set the Append property to False, enter the File Path and set the Overwrite file if exists to True.
    SSIS ZS CSV File Destination - Configure Component Properties Tab

    SSIS ZS CSV File Destination – Configure Component Properties Tab

  6. In the Input Columns Tab, check the columns that you want as load data.
    SSIS ZS CSV File Destination - Configure Input column Tab

    SSIS ZS CSV File Destination – Configure Input column Tab

  7. Click on OK button to save configure setting UI.
  8. Finally, run the package and the data will be exported from source to destination immediately.
    SSIS ZS CSV FIle Destination - Execute the Package

    SSIS ZS CSV FIle Destination – Execute the Package

How to do file split using CSV File Destination.

  1. Double click on CSV File Destination to configure it.
  2. In the Component Properties set Enable File Split to True and File Split Mode BySize.
    SSIS ZS CSV File Destination - File Split

    SSIS ZS CSV File Destination – File Split

  3. Click OK button to save configure setting UI.
  4. That’s all, Now you can run or execute the package and you will see numbers of CSV file in Destination Folder.

How to do file compression using CSV File Destination.

  1. Double click on CSV File Destination to configure it.
  2. In the Component Properties set Compression Type to GZip or Zip and File Split Mode BySize.
    SSIS ZS CSV File Destination - Compression Type

    SSIS ZS CSV File Destination – Compression Type

  3. Click OK button to save configure setting UI. and You can Run or Execute.

How to do the maximum number of rows per file using CSV File Destination.

  1. Double click on CSV File Destination to configure it.
  2. In the Component Properties, you can set Max Rows Per File and Max Size Per File as per your need.
    SSIS ZS CSV File Destination - Max Rows Per File

    SSIS ZS CSV File Destination – Max Rows Per File

  3. Click OK button to save configure setting UI. and You can Run or Execute.

Conclusion

After all, we saw you how to write data into CSV File from SQL Server Table using OLE DB Connection, File Connection, and load into CSV File. We also learned, how to do various things like split CSV File, Compression File and the maximum number of rows per file of data. To explore many other scenarios not discussed in this article download SSIS PowerPack from here (includes 70+ Components).

References

Finally, you can use the following URL for more information.

Posted in SSIS CSV File Destination and tagged , , , , , , , , , , , , .