如何在SQL Server中获取xml列的值

问题描述 投票:0回答:1

如何获取列的XML值?

 SELECT PaymentMethodDetail.value('(/paymentMethodDetail/EFTPaymentDetails/AccountType/text())[0]','varchar(30)') as AccounType,* FROM paymentTable

<PaymentMethodDetail>
  <EFTPaymentDetails paymentMethodCode="">
    <AccountName>RVQNX BASAD</AccountName>
    <AccountType>S</AccountType>
  </EFTPaymentDetails>
</PaymentMethodDetail>

它返回 null 值而不是 S

sql xml xml-parsing sqlxml
1个回答
0
投票

试试这个:

SELECT PaymentMethodDetail.value('(/PaymentMethodDetail/EFTPaymentDetails/AccountType/text())[1]', 'varchar(30)') as AccountType, * 
FROM paymentTable

将 XPath 表达式中的索引从 [0] 更改为 [1]

© www.soinside.com 2019 - 2024. All rights reserved.