Search This Blog

Monday, January 20, 2014

XML exist XQuery SQL Server example

SQL Server > XML > Methods > exist()

Syntax

          exist (XQuery)

Returns

  • 1 : XQuery expression in a query returns a nonempty result
  • 0 : XQuery expression in a query returns an empty result.
  • NULL : if target NULL.

Example: Find specific node in XML


DECLARE @data  XML
.... you xml 

SELECT @data.exist('(//item1)') 'Item1 exists', @data.exist('(//item3)') 'Item3 exists'
Results: