Sort XML Attributes in SQL

2019-09-01 04:06发布

How to sort XML Attributes in SQL?

for example for this XML:

<books><book b='' c='' a=''/></books>

I want:

<books><book a='' b='' c=''/></books>

1条回答
你好瞎i
2楼-- · 2019-09-01 04:56

From http://msdn.microsoft.com/en-us/library/ms187107%28v=sql.90%29.aspx:

The order of the XML attributes is not preserved. When you query the XML instance stored in the xml type column, the order of attributes in the resulting XML may be different from the original XML instance.

So even if you could figure out a way of sorting the attributes, you can not trust that the XML data type in SQL Server will preserve the order you want.

查看更多
登录 后发表回答