How to read and write data to HTML in SSIS

Introduction to read and write data to HTML in SSIS

HTML iconIn this article, we will show how to send values from an SSIS Variable to an HTML file. We will use the SSIS Advanced File System Task to store the list of system files of a folder into a variable and then we will use the SSIS Logging Task to store the variable in an HTML file.

In the second part, we will read values from an HTML table and export the data into SQL Server. We will use the HTML file created in the first example. We will also use the ZS HTML Table Source to read the data from the HTML table and export to SQL Server using the OLEDB Destination.

We will be using this ZappySys SSIS PowerPack component to make things work:

Finally, we will show how to read data from a SQL Server query and store into an HTML file. We will use the Execute SQL Task combined with the ZS SSIS Logging Task.

Requirements

  1. First, you will need SSDT installed.
  2. Secondly, ZappySys PowerPack for SSIS.
  3. Finally, SQL Server installed.

Getting started

How to save the list of system files into SQL an HTML table

In the first example, we will use our ZappySys Advanced File System to copy a list of the system files in a folder. This list of files will be stored in an object variable and then we will save to a file.

  1. In the first place, we will use the Advanced File System Task and select the Get file list ADO.net DataTable action. We will list the files of the c:\sql folder and save the results into a variable:
    SSIS list files

    SSIS list files

  2. In addition, we will create a variable of type object named listfiles that will store the files information:
    SSIS object variable

    SSIS object variable

  3. Also, we will use the ZS Logging Tasks and join with the ZS Advanced File. The ZS Logging Task will be used to store the variable into a file:
    SSIS object variable

    SSIS save variable to HTML

  4. In addition, it is possible to send the variable values into the Execution Log (SSIS output), to a file, to a MessageBox:
    ssis output variable to log messagebo file variable

    SSIS output variable to log, message box and file variable to read and write data to HTML in SSIS

  5. In this example, we will show the values into an HTML file named listfiles.html
    ssis save variable into html

    SSIS save variable iHTMLhtml

  6. After executing the package, you will be able to see the HTML with a list of files, names, size, modification and creation information:
    SSIS list files

    ssis list files

How to copy data from an HTML table to SQL Server

The next example will save data from a file named listfiles.html created in the previous example with an HTML table. The example will export the table to SQL Server. However, with our HTML Table Source, you can export to any destination.

  1. In order to start, we will Drag and drop a data flow task and double click it:
    ssis data flow

    SSIS data flow

  2. Next, in the Data Flow task, use the HTML Table Source and join to the OLEDB Destination:
    ssis html table to oledb

    SSIS HTML table SQL server

  3. Also, in URLs enter the path of the HTML file created in the first example:
    ssis html table read

    SSIS HTML table read

  4. In addition, go to the OLEDB Source, specify the SQL Server name, database, and log in to it.
    In the name of table or view press new to create a new table:
    ssis oledb create table

    SSIS OLEDB create table

  5. Also, go to Mappings page to map all the columns.
    ssis map columns

    SSIS map columns

  6. Finally, run the package and you will have all the data exported.

How to export SQL Server results to an HTML in SSIS

The following example will show how to export the results of an SQL query into an HTML file.

  1. In order to start, we will use the Execute SQL Task. Specify the option Full result set and create an OLEDB connection specifying the Server Name, database name and the select statement to a table:
    ssis sql results

    SSIS SQL query results

  2. Secondly, go to the Result Set page and in the Result Name, set 0 and in Variable name, create a new variable:
    ssis sql result to variable

    ssis sql result to variable

  3. Also, create a variable of type object:
    ssis object data type

    SSIS object data type

  4. Finally, use the ZS Logging Task to save the results in a File. Specify the Log file path and insert the variable:
    ssis save to html file to export data to read and write data to HTML in SSIS

    SSIS save to HTML file

Conclusion about read and write data to HTML in SSIS

To conclude, in this article, we learned how to export a list of files system properties and names to SQL Server. How to read an HTML table to SQL Server and finally how to export SQL Server results to an HTML in SSIS. There are nice tools to read and write data to HTML in SSIS

If you liked the tools, you can download them HERE.

References

Posted in SSIS Advanced File System Task, SSIS HTML Table Source, SSIS Logging Task and tagged , , , , , .