【发布时间】:2015-12-04 12:05:20
【问题描述】:
我有一个带有属性的表
prodid type val
1 colour red
1 size large
2 colour blue
作为一个更大的查询的一部分,我有一个 xml 结构:
(SELECT type "@type",val from t_prodattr pa where pa.prodid=product.id
FOR xml path('attribute'), root('attributes'), type),
给予
<attributes>
<attribute type="colour">
<val>red</val>
</attribute>
<attribute type="size">
<val>small</val>
</attribute>
</attributes>
我希望 xml 成为
<attributes>
<attribute type="colour">red</attribute>
<attribute type="size">small</attribute>
</attributes>
甚至
<attributes>
<colour>red</colour>
<size>small</size>
</attributes>
【问题讨论】:
标签: sql-server xml sql-server-2012