Convert TSQL output into html File

chetan Vishwakarma 146 Reputation points
2021-01-14T10:37:11.41+00:00

Hello Everyone ,

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

Regards
ChetanV

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
Transact-SQL
Transact-SQL
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
    2021-01-14T11:08:01.087+00:00

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

    https://www.red-gate.com/simple-talk/blogs/generating-html-sql-server-queries/

    1 person found this answer helpful.
    0 comments No comments

  2. Yitzhak Khabinsky 25,206 Reputation points
    2021-01-14T15:03:39.673+00:00

    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.

    Benefits:
    • 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
    2021-01-15T07:56:04.987+00:00

    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.

    Regards
    Echo


    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