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
Developer technologies Transact-SQL
SQL Server Other
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 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/

    2 people found this answer helpful.
    0 comments No comments

  2. Yitzhak Khabinsky 26,586 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,621 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.