dahui
dahui

Reputation: 2166

Get unique list of top level element names in XML column of SQL table

I have a query which returns a column of XML values, for simplicity let's say this query is:

select top 1000 XmlColumn from MyTable

This returns a column with 1000 values, these contain XML.

I would like to extract the element name from only the top level element. So then I can transform these into a table of distinct element names.

How can I do this in one query?

Upvotes: 0

Views: 109

Answers (1)

Whencesoever
Whencesoever

Reputation: 2296

 select  XmlColumn.value('local-name(/*[1])','varchar(100)')
 from MyTable

Upvotes: 2

Related Questions