Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 XPath检查一个条目是否存在所有提供的元素对_Sql Server 2008_Xpath - Fatal编程技术网

Sql server 2008 XPath检查一个条目是否存在所有提供的元素对

Sql server 2008 XPath检查一个条目是否存在所有提供的元素对,sql-server-2008,xpath,Sql Server 2008,Xpath,我将以下XML存储在SQLServer2008数据库的XML字段中 <attributes> <attribute> <key>animal</key> <value>rat</value> </attribute> <attribute> <key>color</key> <value>black</value&g

我将以下XML存储在SQLServer2008数据库的XML字段中

<attributes>
  <attribute>
    <key>animal</key>
    <value>rat</value>
  </attribute>
  <attribute>
    <key>color</key>
    <value>black</value>
  </attribute>
</attributes>
如何检查具有多个属性的匹配项

我试图找到:(Key=Animal&Value=Rat)和(Key=Color&Value=Black)之间的行

(是的,我可以在我的WHERE子句中添加另一个.exist和AND,但我正在努力避免)


如果你能带领我朝着正确的方向前进,我会给你加分,让这一切充满活力。我希望有一个存储过程或函数,它可以以某种方式获取键/值对列表,并找到与提供的所有内容匹配的所有行。

XPath允许嵌套谓词和多个谓词。你可以写

/attributes[attribute[key="animal" and value="rat"]][attribute[key="color" and value="black"]]
或者相等,但是稍微短一些

/attributes[attribute[key="animal"]/value="rat" and attribute[key="color"]/value="black"]

为什么您试图避免出现第二个
,并且存在
?你认为这会带来更好的表现吗?我想比较一下所有的可能性。您认为AND EXISTS的性能会比Markusk提供的xpath好吗?+1是我唯一能找到的SQL Server中存在
.exist()=1
语法的文档。
/attributes[attribute[key="animal"]/value="rat" and attribute[key="color"]/value="black"]