2

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

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

SELECT * 
FROM   ORDER 
WHERE  ORDERXML.EXISTS('/Order/header/status/text()="Processing"') = 1 
Gidil
  • 4,137
  • 2
  • 34
  • 50
Bhalchandra K
  • 2,631
  • 3
  • 31
  • 43
  • possible duplicate of [How can I query a value in SQL Server XML column](http://stackoverflow.com/questions/10344553/how-can-i-query-a-value-in-sql-server-xml-column) – Gidil Jul 24 '14 at 07:12
  • i don't understand is the question not clear? why down voting and closing? – Bhalchandra K Jul 24 '14 at 07:13
  • I didn't down vote your Q. I suggest you follow the link in my prev comment, I think you'll find the answer there. – Gidil Jul 24 '14 at 07:15
  • The shared link is useful. – Bhalchandra K Jul 24 '14 at 07:24
  • 1
    Then you agree that this post is a duplicate? Try to do some searching first next time before you post a Q :-) – Gidil Jul 24 '14 at 07:24
  • I agree. other perspective, if you check the question subject/title, it is useful for next search from google. Google pops up most relevant searched texts. – Bhalchandra K Jul 24 '14 at 07:31

1 Answers1

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.

select O.*
from [Order] as O
where O.OrderXML.exist('/Order/header/status[text() = "Processing"]') = 1
Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281