HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Select XML values when attribute involved

Submitted by: @import:stackexchange-dba··
0
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?

Solution

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.

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.