简体   繁体   English

SQL Server XQuery选择“ XML列”是否包含具有值的元素的记录

[英]SQL Server XQuery to select record if XML Column contains element with value

I want to select the records from the Orders table. 我想从“订单”表中选择记录。 It contains the OrderXML as XML type column. 它包含OrderXML as XML type列。

if OrderXML has order with status given by user then it should select the record. 如果OrderXML具有用户指定状态的订单,则应选择记录。 I am trying following query but not working - 我正在尝试跟踪查询,但无法正常工作-

SELECT * 
FROM   ORDER 
WHERE  ORDERXML.EXISTS('/Order/header/status/text()="Processing"') = 1 

You need to put the predicate within brackets and exist need to be lower case. 您需要将谓词放在方括号中,并且exist的谓词必须是小写的。 XML is case sensitive and even the XML function names in SQL Server is case sensitive. XML区分大小写,即使SQL Server中的XML函数名称也区分大小写。

select O.*
from [Order] as O
where O.OrderXML.exist('/Order/header/status[text() = "Processing"]') = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM