Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a table that stores XML values in field: OtherData.

An XML value from one row:

< file path="C:\WINDOWS\system32\svchost.exe" />

I would like to select all rows that have an attribute path like '%svchost%'

What is the right SQL query to do this?

share|improve this question

Use the XQuery CONTAINS method, like this:

SELECT CASE @x.exist
N'/bikes/Product[1]/Specifications[contains(., "Novice")]'
WHEN 1 THEN N'The bike is good for novices'
WHEN 0 THEN N'The bike is for more advanced riders'

Good luck.

share|improve this answer
Can you add a reference to where you copy/pasted that please? Not least for more information – gbn Mar 15 '11 at 17:32
up vote 3 down vote accepted

I used an XQUERY approach but different from yours (@Allen White):

Select * From Table where OtherData.value('(/file/@path)[1]', 'varchar (1000)') LIKE '%svchost.exe%' 
share|improve this answer
+1 simple and straight forward! You can mark this as answered! – CoderHawk Mar 17 '11 at 4:46
thanks, I just marked it :) – yrushka Mar 21 '11 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.