【发布时间】:2013-08-08 17:14:26
【问题描述】:
我有一个分层数据表,我试图将其选择为单个分组的 XML 值:
列:Id, Type, SubType, SubSubType
样本数据:
Id Type Subtype SubSubType
1 Product Documentation Brochures Functional Brochures
2 Product Documentation Brochures Fliers
3 Product Documentation Data Sheets and Catalogs Data Sheets
4 Product Documentation Data Sheets and Catalogs Catalogs
5 Other Documentation Other classification User Guides
对于以上数据,我想输出如下xml:
<AllTypes>
<Type name="Product Documentation">
<SubType name="Brochures">
<SubSubType name="Functional Brochures"/>
<SubSubType name="Fliers"/>
</SubType>
<SubType name="Data Sheets and Catalogs">
<SubSubType name="Data Sheets"/>
<SubSubType name="Catalogs"/>
</SubType>
</Type>
<Type name="Other Documentation">
<SubType name="Other classification">
<SubSubType name="User Guides"/>
</SubType>
</Type>
</AllTypes>
即包含上表中所有行的单个 xml 结构,按第一列 (Type) 分组,并按第二列 (SubType) 进一步分组。
【问题讨论】:
-
欢迎来到
stackoverflow。描述得很好!。请分享您迄今为止尝试过的示例代码,以便其他用户可以轻松帮助您。
标签: sql sql-server-2008 sqlxml