XQuery exist method

Sam picture Sam · Aug 16, 2012 · Viewed 9.3k times · Source

How do I check against multiple values in XQuery exist method? I'm running this XQuery in a SQL statement

Select [column1] [xmlcolumn] from tablet
where [xmlcolumn].exist('/node/subnode/subsubnode[.="value1"]') = 1

I want to be able specify multiple values like [.="value1" OR "value2" OR ...].

Any pointers is appreciated.

Answer

Dimitre Novatchev picture Dimitre Novatchev · Aug 17, 2012

Use:

exists(/node/subnode/subsubnode[. eq "value1" or . eq "value2"])

XPath is case-sensitive, the operator to use is "or" -- not "OR".

If you have many values, it is more practical to use:

exists(/node/subnode/subsubnode
              [. = ("value1","value2","value3","value4","value5")])