patternMinor
Select XML values when attribute involved
Viewed 0 times
xmlattributewhenvaluesselectinvolved
Problem
I have a table that stores XML values in field: OtherData.
An XML value from one row:
I would like to select all rows that have an attribute path like '%svchost%'
What is the right SQL query to do this?
An XML value from one row:
I would like to select all rows that have an attribute path like '%svchost%'
What is the right SQL query to do this?
Solution
Use the XQuery CONTAINS method, like this:
Good luck.
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.
Code Snippets
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;Context
StackExchange Database Administrators Q#1748, answer score: 4
Revisions (0)
No revisions yet.