exist() Method
XQuery existence test
What changes
- Input
- xml instance and XQuery
- Output or change
- bit
Syntax at a glance
exist (XQuery)
Work example
Filter rows by whether an XML path contains a matching node.
Use exist in the predicate and include a specific node condition rather than extracting text first.
Check your work exist returns 1 or 0 for a matching sequence and can return null for a null XML instance.
Practice SQL
Open in SQL FlowDECLARE @doc xml = N'<Order><Item quantity="2" /></Order>'; SELECT @doc.exist('/Order/Item[@quantity > 1]') AS has_large_item;
Open Microsoft Learn for full syntax, permissions, and details for your version.