5

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?

jcolebrand
6,3764 gold badges43 silver badges67 bronze badges
asked Mar 15, 2011 at 11:56

2 Answers 2

4

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.

gbn
70.3k8 gold badges168 silver badges244 bronze badges
answered Mar 15, 2011 at 12:28
1
  • 2
    Can you add a reference to where you copy/pasted that please? Not least for more information Commented Mar 15, 2011 at 17:32
4

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%' 
Sandeep Kumar M
4,6823 gold badges33 silver badges35 bronze badges
answered Mar 16, 2011 at 13:42
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.