2
xmlファイルからChargeTypeの値を取得するtsqlを使用します。 私はスクリプトを書いていましたが、両方のxmlレコードの値 'Principal'を常に返します。 何が間違っていて問題を解決する方法がわかりませんか?スクリプトは、値を返す必要があります。TSQL XML値は、すべてのレコードのノードの最初の値を返します
ChargeType
Principal
Taxed
現在の結果
ChargeType
Principal
Principal
ソースコード
DECLARE @xml XML = '<ListFinancialEventsResponse xmlns="http://www.test.com">
<ListFinancialEventsResult>
<FinancialEvents>
<ShipmentEventList>
<ShipmentEvent>
<ShipmentItemList>
<ShipmentItem>
<ItemChargeList>
<ChargeComponent>
<ChargeType>Principal</ChargeType>
<ChargeAmount>
<CurrencyAmount>20.4</CurrencyAmount>
<CurrencyCode>RUR</CurrencyCode>
</ChargeAmount>
</ChargeComponent>
<ChargeComponent>
<ChargeType>Taxed</ChargeType>
<ChargeAmount>
<CurrencyAmount>1.23</CurrencyAmount>
<CurrencyCode>GEL</CurrencyCode>
</ChargeAmount>
</ChargeComponent>
</ItemChargeList>
</ShipmentItem>
</ShipmentItemList>
</ShipmentEvent>
</ShipmentEventList>
</FinancialEvents>
</ListFinancialEventsResult>
</ListFinancialEventsResponse>';
;WITH XMLNAMESPACES('http://www.test.com' as ns)
select
lfer.c.value('(//ns:ChargeType)[1]', 'nvarchar(50)') AS ChargeType
from @xml.nodes('//ns:ListFinancialEventsResponse//ns:ListFinancialEventsResult//ns:ShipmentItemList//ns:ShipmentItem//ns:ItemChargeList//ns:ChargeComponent') lfer(c)