I\'ve got a table which has a XML field. The typical XML it contains is;
39
What i'm trying to achieve is a way of saying, across all xml data in the whole table... give me all of the xmlElements where the title is X.
Not sure if I totally understood your question here - or are you looking for this? You would grab all the /things/Fruit elements a "nodes" and cross join them against your "base data" in the myTable - the result would be one row per XML element in your XML data field:
select
omID,
T.Fruit.query('.')
from
dbo.myTable
cross apply
omText.nodes('/things/Fruit') as T(Fruit)
where
T.Fruit.value('(title)[1]', 'varchar(50)') = 'X'
Or give me a count of all items that use an imageId of 55.
select
count(*)
from
dbo.myTable
cross apply
omText.nodes('/things/Fruit') as T(Fruit)
where
T.Fruit.value('(imageId)[1]', 'int') = 55
Is that what you're looking for?
Marc