HtmlTables
Retrieves HTML Tables from an HTML string and returns a table
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT *
FROM SQLHTTP.net.HtmlTables ( @Html )
Name | Type | Description |
---|---|---|
@Html | nvarchar(MAX) | String containing HTML |
Column name | Data type | Description | |||
---|---|---|---|---|---|
RowID | int | Row Index | |||
ParentRowID | int | The RowID of the containing (parent) table, if any. | |||
StartPosition | int | Start position of the
tag |
|||
HtmlTable | nvarchar(MAX) | Content |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
DECLARE @Html nvarchar(MAX) SET @Html = N' <html> <head> <title>Daylight saving time</title> </head> <body> <table> <tr> <td> This cell is inside the first outermost table <table> <tr> <td> This cell is inside the first table, inside the first outermost table </td> </tr> </table> <table> <tr> <td> This cell is inside the second table, inside the first outermost table </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> This cell is inside the second outermost table </td> <tr> </table> </body> </html>' SELECT RowID, ParentRowID, StartPosition, EndPosition, LEFT(REPLACE(HtmlTable, CHAR(13) + CHAR(10), ''), 20) + '...' AS PartialHtmlTable FROM SQLHTTP.net.HtmlTables(@Html) |
1 2 3 4 5 6 7 8 |
RowID ParentRowID StartPosition EndPosition PartialHtmlTable ----------- ------------- ------------- ----------- ------------------- 1 NULL 79 490 <table... 2 1 159 304 <table... 3 1 311 457 <table... 4 NULL 494 600 <table... |