解析具有多个同名元素的 OpenXML
我有一个这样的数据结构:
<rootnode>
<group>
<id>1</id>
<anothernode>first string</anothernode>
<anothernode>second string</anothernode>
</group>
<group>
<id>2</id>
<anothernode>third string</anothernode>
<anothernode>fourth string</anothernode>
</group>
</rootnode>
以及以下代码:
EXEC sp_xml_preparedocument @index OUTPUT, @XMLdoc
SELECT *
FROM OPENXML (@index, 'rootnode/group')
WITH
(
id int 'id',
anothernode varchar(30) 'anothernode'
)
它给出了结果
id | anothernode
————————————————
1 | first string
2 | third string
我怎样才能让它显示这个结果,而不是显示所有四个字符串?
id | anothernode
————————————————
1 | first string
1 | second string
2 | third string
2 | fourth string
I have a data structure as such:
<rootnode>
<group>
<id>1</id>
<anothernode>first string</anothernode>
<anothernode>second string</anothernode>
</group>
<group>
<id>2</id>
<anothernode>third string</anothernode>
<anothernode>fourth string</anothernode>
</group>
</rootnode>
And the following code:
EXEC sp_xml_preparedocument @index OUTPUT, @XMLdoc
SELECT *
FROM OPENXML (@index, 'rootnode/group')
WITH
(
id int 'id',
anothernode varchar(30) 'anothernode'
)
which gives me the result
id | anothernode
————————————————
1 | first string
2 | third string
How can I get it to show this result instead where all four strings are showing instead?
id | anothernode
————————————————
1 | first string
1 | second string
2 | third string
2 | fourth string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者您可以使用 XML 数据类型,如下所示:
Or you can use the XML datatype instead like this: