これが私のxmlがどのように見えるかです:
<Company xmlns ="http://abc.com/rules">
<Employee id="E1" number="0000007535">
<Payment disposition="Open" type="ABC" amount_paid="100.00" />
<Payment disposition="Closed" type="XYZ" amount_paid="468.00" />
<Payment disposition="Open" type="AOD" amount_paid="156.00" />
<Payment disposition="Closed" type="ONB" amount_paid="2834.00" />
</ Employee >
<Employee id="E1" number="0000007536">
<Payment disposition="Open" type="DFG" amount_paid="200.00" />
<Payment disposition="Closed" type="HFK" amount_paid="568.00" />
</ Employee >
<Employee id="E1" number="0000007537">
<Payment disposition="Open" type="TTT" amount_paid="600.00" />
<Payment disposition="Closed" type="BBB" amount_paid="368.00" />
</ Employee >
<Employee id="E2" number="0000007541">
<Payment disposition="Open" type="EEE" amount_paid="0.00" />
<Payment disposition="Closed" type="WWW" amount_paid="568.00" />
<Payment disposition="Closed" type="GHW" amount_paid="968.00" />
</ Employee >
<Employee id="E2" number="0000007542">
<Payment disposition="Open" type="QQQ" amount_paid="140.00" />
<Payment disposition="Closed" type="CCC" amount_paid="68.00" />
</ Employee >
<Employee id="E3" number="0000007551">
<Payment disposition="Open" type="AAA" amount_paid="300.00" />
<Payment disposition="Closed" type="TTT" amount_paid="668.00" />
</ Employee >
</ Company>
各従業員のすべての支払い情報を取得する必要があります
何かのようなもの :
E10000007535オープンABC100.00
E10000007536クローズXYZ468.00
.....。
E2 0000007541EEE0.00を開き
ます...。
ただし、以下のコードでは、Dispositon、Type、およびAmountPaidのみが表示され、各従業員にマップすることはできません。
;WITH XMLNAMESPACES (DEFAULT 'http://abc.com/rules')
select Disposition,Type,AmountPaid from
EMPLOYEE
OUTER APPLY
(
SELECT
tbl.col.value('(@disposition)[1]','varchar(20)') AS Disposition,
tbl.col.value('(@type)[1]','varchar(20)') AS Type,
tbl.col.value('(@amount_paid)[1]','varchar(20)') AS AmountPaid
FROM xmldocument.nodes('//Employee/Payment') AS tbl(col)
)Z
WHERE xmlid = 500
ありがとうBB