与此问题类似,但我需要根据特定属性进行解析。如何根据属性值只选择一个同名元素?
DECLARE @doc int
EXEC sp_xml_preparedocument @doc OUTPUT, N'
<rootnode>
<group>
<id>1</id>
<anothernode lang="de">first string</anothernode>
<anothernode lang="en">second string</anothernode>
</group>
<group>
<id>1</id>
<anothernode lang="en">I</anothernode>
<anothernode lang="de">Ich</anothernode>
</group>
</rootnode>'
SELECT *
FROM OPENXML (@doc, 'rootnode/group')
WITH
(
id int 'id',
anothernode varchar(30) 'anothernode'
)
EXEC sp_xml_removedocument @doc
结果是:
1 first string
2 Ich
我需要:
1 second string
2 I