Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

2 Answers 2

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'
END;

Good luck.

share|improve this answer
2  
Can you add a reference to where you copy/pasted that please? Not least for more information –  gbn Mar 15 '11 at 17:32
add comment
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! –  Coder Hawk Mar 17 '11 at 4:46
    
thanks, I just marked it :) –  yrushka Mar 21 '11 at 8:38
add comment

Your Answer

 
discard

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.