如何使用XQuery选择XML节点的内部文本?

Microsoft Books Online显示了如何在下面检索属性:

DECLARE @myDoc xml
DECLARE @ProdID int
SET @myDoc = '<Root>
<ProductDescription ProductID="1" ProductName="Road Bike">
<Features>
  <Warranty>1 year parts and labor</Warranty>
  <Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
</Root>'

SET @ProdID =  @myDoc.value('(/Root/ProductDescription/@ProductID)[1]', 'int' )
SELECT @ProdID

如何获取保修节点的内部文本值?

有帮助吗?

解决方案

这样的事情:

DECLARE @Warranty VARCHAR(50)

SET @Warranty = @myDoc.value('(/Root/ProductDescription/Features/Warranty/text())[1]', 'varchar(50)' )

SELECT @Warranty

马克

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top