Convert of HTML

SVA 116 Reputation points
2024-07-10T12:41:12.3666667+00:00

Hello

How to convert the html data in a table column to table format and store in another table

Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,923 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zahid Butt 956 Reputation points
    2024-07-10T13:37:53.81+00:00

    Hi,

    Below is sample code:

    DECLARE @html xml =

    '

    <html>

    <header><title>Test</title></header>

    <body>

    <h1>blah blah</h1>

    <table border="1" cellspacing="0" style="border: black 1px solid">

    <tr><th>Date</th><th>Sales</th></tr>

    <tr><td>1/1/2003</td><td>12.09</td></tr>

    <tr><td>1/3/2003</td><td>85.09</td></tr>

    </table>

    <p>blah blah</p>

    </body>

    </html>

    '

    -- code to get extract data from the HTML

    SELECT sale_date = xx.value('(./td/text())[1]','varchar(100)'),

    sale_amt = xx.value('(./td/text())[2]','varchar(100)')

    into #SQL_Table

    FROM (values(@html)) t1(x)

    CROSS APPLY x.nodes('//table[1]/tr[position()>1]') t2(xx);

    select * from #SQL_Table

    You may get it from here."https://www.sqlservercentral.com/forums/topic/import-data-from-html-document-into-sql-table"

    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.