Convert TSQL output into html File

chetan Vishwakarma 146 Reputation points

Hello Everyone ,

Is there any way where to convert my TSQL query output to physical html file?


SQL Server on Azure Virtual Machines
Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,899 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,563 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 41,411 Reputation points

    You can use simple T-SQL string function to get a query result in Html table format, see for example

    1 person found this answer helpful.
    0 comments No comments

  2. Yitzhak Khabinsky 25,206 Reputation points

    It seems that your question contains two parts:

    1. HTML generation via T-SQL.
    2. Create a physical html file on the file system.

    First part
    (X)HTML composition is relatively easy to implement in T-SQL by using T-SQL and XQuery.
    It is much better approach in comparison with string concatenation.

    • It creates a guaranteed proper (X)HTML.
    • Easy to test in both SSMS and any internet browser.
    • It is dynamic and can handle both SQL variables and tables.
    • It supports both CSS styles: embedded and included.

    Check it out here my answers on the forum on the same subject:

    Second part
    bcp, command line utility, can generate a file on the file system based on a query.

    0 comments No comments

  3. EchoLiu-MSFT 14,571 Reputation points

    Hi @chetan Vishwakarma ,

    If you just want to generate html format from the output of sql server, the methods provided by the above two experts can be used. But if you want to generate a physical html file from the output, you may need ssis to achieve it.

    If you have any question, please feel free to let me know.


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments