How to sort the data of the MS SQL table in an XML type column so that all tags go in alphabetical order (by tag name)?

Example

    1 answer 1

    You can treat xml as a string:

    select * from #t order by cast(dxml as nvarchar(max)) 

    You can use the tag name:

     select * from #t order by dxml.value('local-name(/*[1])', 'nvarchar(max)')