如果XML列包含具有值的元素,则SQL Server XQuery选择记录

时间:2021-12-25 17:04:46

I want to select the records from the Orders table. It contains the OrderXML as XML type column.

我想从Orders表中选择记录。它包含OrderXML作为XML类型列。

if OrderXML has order with status given by user then it should select the record. I am trying following query but not working -

如果OrderXML的订单状态由用户提供,那么它应该选择记录。我正在尝试以下查询但不工作 -

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

1 个解决方案

#1


3  

You need to put the predicate within brackets and exist need to be lower case. 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

#1


3  

You need to put the predicate within brackets and exist need to be lower case. 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