Main Topics
Browse All TopicsI have a table which has a column Properties (as XML) and some other normal nvarchar columns (title, description, etc).
The XML column contains data like this:
<config>
<props>
<prop type='category'>house</pro
<prop type='category'>garage</pr
</props>
<config>
Now I want to do a select on every row which contains a prop/@type:category with the value garage.
Is this possible in SQL 2008.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Also general concepts XML Document Object Model (DOM) are here
http://msdn.microsoft.com/
I know XML and XPath, that's not my issue. I am trying to Query on an XML datatype in MS SQL 2008:
Let's say we have a table with a few columns:
id int
title nvarchar(50)
description nvarchar(1000)
properties xml
isPublic bit
Now I have a XML in the column properties:
<config>
<props>
<prop type='category'>house</prop>
<prop type='category'>garage</prop
<prop type='size'>large</prop>
</props>
<config>
I want to query on the XML properties in my XML file:
Let's say I want all the records where in the XML datacolumn we have a property [@category='name'] with a textvalue 'garage'
I.E.
SELECT title, description, properties FROM TABLE_X WHERE isPublic = 1 and properties[HOW TO USE XPATH HERE?]
Update
I can use the method query() in my select but only as a selector:
... and properties.query('/config/
or
... and properties.exist('/config/
But this returns an error:
An expression of non-boolean type specified in a context where a condition is expected.
I figured out that I can query on string based nodes:
WHERE PROPERTIES.exist('
/config/props/prop[@type="
PROPERTIES.exist('
/config/props/prop[@type="
this works like a charm, I am testing this on a database with > 100000 records. It takes just milliseconds to return the results.
The only thing I still can't figure out is how to query on an integer, i.e. NODE VALUE > 100
Business Accounts
Answer for Membership
by: MS_help_guyPosted on 2009-03-06 at 08:20:26ID: 23818090
Try to Use:
select * from [NAME] where prop/@type:category