--- title: "Specifying Boolean Functions in XPath Queries (SQLXML 4.0) | Microsoft Docs" ms.custom: "" ms.date: "03/17/2017" ms.prod: "sql-server-2016" ms.reviewer: "" ms.suite: "" ms.technology: - "dbe-xml" ms.tgt_pltfrm: "" ms.topic: "reference" helpviewer_keywords: - "XPath queries [SQLXML], Boolean functions" - "false function" - "not function [SQLXML]" - "true function" - "Boolean functions" ms.assetid: c72cd333-9294-4d41-84f2-1748bf20e3eb caps.latest.revision: 26 author: "douglaslMS" ms.author: "douglasl" manager: "jhubbard" --- # Specifying Boolean Functions in XPath Queries (SQLXML 4.0) The following examples show how Boolean functions are specified in XPath queries. The XPath queries in these examples are specified against the mapping schema contained in SampleSchema1.xml. For information about this sample schema, see [Sample Annotated XSD Schema for XPath Examples (SQLXML 4.0)](../../../relational-databases/sqlxml-annotated-xsd-schemas-xpath-queries/samples/sample-annotated-xsd-schema-for-xpath-examples-sqlxml-4-0.md). ## Examples ## A. Specify the not() Boolean function This query returns all the **\** child elements of the context node that do not have **\** child elements: ``` /child::Customer[not(child::Order)] ``` The **child** axis is the default. Therefore, the query can be specified as: ``` /Customer[not(Order)] ``` #### To test the XPath query against the mapping schema 1. Copy the [sample schema code](../../../relational-databases/sqlxml-annotated-xsd-schemas-xpath-queries/samples/sample-annotated-xsd-schema-for-xpath-examples-sqlxml-4-0.md) and paste it into a text file. Save the file as SampleSchema1.xml. 2. Create the following template (BooleanFunctionsA.xml) and save it in the directory where SampleSchema1.xml is saved. ``` Customer[not(Order)] ``` The directory path specified for the mapping schema (SampleSchema1.xml) is relative to the directory where the template is saved. An absolute path also can be specified, for example: ``` mapping-schema="C:\MyDir\SampleSchema1.xml" ``` 3. Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the template. For more information, see [Using ADO to Execute SQLXML 4.0 Queries](../../../relational-databases/sqlxml/using-ado-to-execute-sqlxml-4-0-queries.md). Here is the partial result set of the template execution: ``` ... ``` ## B. Specify the true() and false() Boolean functions This query returns all **\** element children of the context node that do not have **\** child elements. In relational terms, this query returns all customers who have not placed any orders. ``` /child::Customer[child::Order=false()] ``` The **child** axis is the default. Therefore, the query can be specified as: ``` /Customer[Order=false()] ``` This query is equivalent to the following: ``` /Customer[not(Order)] ``` The following query returns all the customers who have placed at least one order: ``` /Customer[Order=true()] ``` This query is equivalent to this one: ``` /Customer[Order] ``` #### To test the XPath query against the mapping schema 1. Copy the [sample schema code](../../../relational-databases/sqlxml-annotated-xsd-schemas-xpath-queries/samples/sample-annotated-xsd-schema-for-xpath-examples-sqlxml-4-0.md) and paste it into a text file. Save the file as SampleSchema1.xml. 2. Create the following template (BooleanFunctionsB.xml) and save it in the directory where SampleSchema1.xml is saved. ``` /Customer[Order=false()] ``` The directory path specified for the mapping schema (SampleSchema1.xml) is relative to the directory where the template is saved. An absolute path also can be specified, for example: ``` mapping-schema="C:\MyDir\SampleSchema1.xml" ``` 3. Create and use the SQLXML 4.0 Test Script (Sqlxml4test.vbs) to execute the template. For more information, see [Using ADO to Execute SQLXML 4.0 Queries](../../../relational-databases/sqlxml/using-ado-to-execute-sqlxml-4-0-queries.md). Here is the partial result set of the template execution: ``` ... ```