My table @T have a XML column xmlcol on SQL Server 2005. I want to query all the rows where certain node contains a particular value.
declare @T table(xmlcol Xml)
insert into @T values('
<root>
<items>
<item>
<x1>
<id>12345678</id>
</x1>
<x2>
<count>12</count>
</x2>
</item>
<item>
<x1>
<id>99999999</id>
</x1>
<x2>
<count>10</count>
</x2>
</item>
</items>
</root>')
select
[xmlcol].query('/root/items/item')
from @T
where
[xmlcol].exist('/root/items/item/x1/id[contains(.,"12345678")]') = 1
This query shows all , but I need only show ONE , like this:
<item>
<x1>
<id>12345678</id>
</x1>
<x2>
<count>12</count>
</x2>
</item>
I found similar question, but with values only, and I am not able to rewrite query for show nodes. Is it possible to select part of xml which I need?
thanks