如何获取列的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
试试这个:
SELECT PaymentMethodDetail.value('(/PaymentMethodDetail/EFTPaymentDetails/AccountType/text())[1]', 'varchar(30)') as AccountType, *
FROM paymentTable
将 XPath 表达式中的索引从 [0] 更改为 [1]