2009-03-09 6 views
1

Comment sélectionner le texte interne d'un noeud XML à l'aide de XQuery?Utilisation de XQuery dans SQL Server 2005 pour obtenir le code XML interne

Microsoft Books montre en ligne comment retrive un attribut ci-dessous:

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 

Comment pourrais-je obtenir la valeur de texte interne du nœud de garantie?

Répondre

5

Quelque chose comme ceci:

DECLARE @Warranty VARCHAR(50) 

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

SELECT @Warranty 

Marc

Questions connexes