以下是我的XML的样子。我试图在SQL Server 2008中查询XML。我想显示基于ID的所有声明。
<clue xmlns="http://cp.com/rules/client">
<claim unit_number="1" number="0000007517" id="S1"
sequence_number="1">
<scope_of_claim>Full scope</scope_of_claim>
</claim>
<claim unit_number="1" number="0000007518" id="S1"
sequence_number="2">
<scope_of_claim>Full scope</scope_of_claim>
</claim>
</clue>
我的查询:
以下查询仅为我提供了第一项索赔的值。
;WITH XMLNAMESPACES (DEFAULT 'http://cp.com/rules/client')
select xmldocument.value('(//claim/@number)[1]','varchar(20)') as ClaimNumber,
xmldocument.value('(//claim/scope_of_claim)[1]','varchar(20)') as Scope
.....
from clue.xml
我如何获得所有索赔?
答案 0 :(得分:2)
;WITH XMLNAMESPACES (DEFAULT 'http://cp.com/rules/client')
SELECT xmlid,
ClaimNumber,
Scope
FROM clue.xml
OUTER APPLY
(SELECT
tbl.col.value('(@number)[1]', 'varchar(20)') AS ClaimNumber,
tbl.col.value('(scope_of_claim)[1]', 'varchar(20)') AS Scope
FROM xmldocument.nodes('//claim') AS tbl(col)) x