【发布时间】:2016-10-28 13:32:34
【问题描述】:
我有如下查询(示例)。
Select 'Somthing' as Title,
'Some notes' as Notes,
(Select Path1
From (Select 'One' Path1
union
Select 'Two' Path1
union
Select 'Three' Path1) T
FOR XML PATH('Image'),ROOT('Images'), ELEMENTS, TYPE),
'Other value' as Value
FOR XML PATH('ItemRow'),TYPE,ELEMENTS
xml下面的输出
<ItemRow>
<Title>Somthing</Title>
<Notes>Some notes</Notes>
<Images>
<Image>
<Path1>One</Path1>
</Image>
<Image>
<Path1>Two</Path1>
</Image>
<Image>
<Path1>Three</Path1>
</Image>
</Images>
<Value>Other value</Value>
</ItemRow>
我正在尝试将注释和图像放入父节点,所以它应该如下所示
<ItemRow>
<Title>Somthing</Title>
<SomeParentNode>
<Notes>Some notes</Notes>
<Images>
<Image>
<Path1>One</Path1>
</Image>
<Image>
<Path1>Two</Path1>
</Image>
<Image>
<Path1>Three</Path1>
</Image>
</Images>
</SomeParentNode>
<Value>Other value</Value>
</ItemRow>
这可能吗?
【问题讨论】:
标签: sql-server xml sql-server-2012 for-xml-path