Skip to content
Advertisement

How to query all occurences of a header of a XML column in SQL Server

I have a table with a column named [xml] of type varchar(max) column with HTML Tables in each line, such as:

in a Microsoft SQL Server 2008 R2.

I want to know how many occurrences of a table header there is. I have inconsistencies because all headers were supposed to be the same, but they are not. I have to discover where to look. An expected result would be something like:

I am trying to use the question (SQL) Identify positions of multiple occurrences of a string format within a field , with this REGEX: <th[^>]+>[^<]+</th>. But even when I try select * where [XML] like '%<th[^>]+>[^<]+</th>%' it doesn’t work. I used Regex101 to create this pattern.

Advertisement

Answer

If interested in a helper function.

Example

Returns

The Function If Interested

Advertisement