0

XML file

<?xml version="1.0" encoding="utf-8"?>
<Data>
  <ProductID>
    <Producer value="SomeName" />
    <Locality value="California" />
    <Chamber value="ATK-01B" />
    <System value="CAL-ATK-01B-01" />
  </ProductID>     
</Data>

The above is the XML file gets saved in the column content of a SQL Server table. I am using the below query to select the records from DB with value CAL-ATK-01B-01.

Query:

SELECT * 
FROM [Table name] 
WHERE [xmlBody].value('(/Data/ProductID/System)[1]', 'varchar(max)') LIKE 'CAL-ATK-01B-01';  

I need to select all records with matching value in xml file as "CAL-ATK-01B-01". But the query I tried is returning empty value.

Can any one help me do this?

Thanks

0

1 Answer 1

1

You need to use this query here to actually select the value of the XML attribute value:

SELECT * 
FROM [Table Name]
WHERE [xmlBody].value('(/Data/ProductID/System/@value)[1]', 'varchar(100)') LIKE 'CAL-ATK-01B-01';  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.