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?
asked Mar 15, 2011 at 11:56
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.
gbn
70.3k8 gold badges168 silver badges244 bronze badges
answered Mar 15, 2011 at 12:28
user1209user1209
-
2Can you add a reference to where you copy/pasted that please? Not least for more informationgbn– gbn2011年03月15日 17:32:21 +00:00Commented Mar 15, 2011 at 17:32
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
lang-sql