就像其他帖子一样,我需要从表中检索在 Xml 列上应用条件的任何行,例如,假设您有一个这样的 xml 列:
<DynamicProfile xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WinTest">
<AllData xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:KeyValueOfstringstring>
<d2p1:Key>One</d2p1:Key>
<d2p1:Value>1</d2p1:Value>
</d2p1:KeyValueOfstringstring>
<d2p1:KeyValueOfstringstring>
<d2p1:Key>Two</d2p1:Key>
<d2p1:Value>2</d2p1:Value>
</d2p1:KeyValueOfstringstring>
</AllData>
</DynamicProfile>
我的查询将能够返回 node value <d2p1:Key> = 'some key value'
AND node value的所有行<d2p1Value = 'some value value'
。
把它想象成一个动态表,其中 KEY 节点代表列名,Value 节点代表列的值。
以下查询不起作用,因为键和值节点不是连续的:
select * from MyTable where
MyXmlField.exist('//d2p1:Key[.="One"]') = 1
AND MyXmlField.exist('//d2p1:Value[.="1"]') = 1