SQL Server: XML node column order

I was wondering if I CAN ORDER at my request a node of a column with typed XML?

For example, I have a table

ID (int) | Data (XML)

The Data column stores XML in a form similar to this

<?xml?>
<Data>
   <SimpleOrderedValue>1</SimpleOrderedValue>
   <ComplicatedInternals>
      ...
   </ComplicatedInternals>
</Data>

I want to query this table ordered by SimpleOrderedValue. Can I do this on MS SQL Server 2008 with an XML column? Or I can do thins using the CLR UDT, but without an extra computed column and so that the Data column is indexed (for faster searches).

Thanks any help. Thank.

+3
source share
1 answer

How about an XQuery expression ,

select id, data
from T
  order by data.value('(/Data/SimpleOrderedValue)[1]', 'int') 
+4

Source: https://habr.com/ru/post/1747354/


All Articles