---
title: "Specifying Boolean-Valued Predicates in XPath Queries (SQLXML 4.0) | Microsoft Docs"
ms.custom: ""
ms.date: "03/16/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], predicates"
- "nested predicates"
- "successive predicates"
- "predicates [SQLXML]"
- "top-level predicates"
- "Boolean-valued predicates"
- "multiple predicates"
ms.assetid: 5f6e7219-6911-4bca-a54b-56b95e0b43dd
caps.latest.revision: 25
author: "douglaslMS"
ms.author: "douglasl"
manager: "jhubbard"
---
# Specifying Boolean-Valued Predicates in XPath Queries (SQLXML 4.0)
The following examples show how Boolean-valued predicates 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 multiple predicates
The following XPath query uses multiple predicates to find order information for a given order ID and a customer ID:
```
/child::Customer[attribute::CustomerID="1"]/child::Order[attribute::OrderID="Ord-43860"]
```
A shortcut to the `attribute` axis (@) can be specified, and because the `child` axis is the default, it can be omitted from the query:
```
/Customer[@CustomerID="1"]/Order[@SalesOrderID="Ord-43860"]
```
##### 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 (BooleanValuedPredicatesA.xml) and save it in the directory where SampleSchema1.xml is saved.
```
/Customer[@CustomerID="1"]/Order[@SalesOrderID="Ord-43860"]
```
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 result:
```
```
### B. Specify successive and nested predicates
The following query shows using successive predicates. The query returns all the **\** child elements of the context node that have both a **SalesPersonID** attribute with a value of 277 and a **TerritoryID** attribute with a value of 3:
```
/child::Customer[attribute::SalesPersonID="277"][attribute::TerritoryID="3"]
```
The query returns the **\** elements that satisfy both the conditions specified in the predicates.
A shortcut to the **attribute** axis (@) can be specified, and because the **child** axis is the default, it can be omitted from the query:
```
/Customer[@SalesPersonID="277"][@TerritoryID="3"]
```
The following XPath query illustrates the use of nested predicates. The query returns all the **\** child elements of the context node that include **\** child elements with at least one **\** element that has a **SalesPersonID** attribute value of 2.
```
/Customer[Order[@SalesPersonID=2]]
```
##### 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 (nestedSuccessive.xml) and save it in the directory where SampleSchema1.xml is saved.
```
/Customer[@SalesPersonID="277"][@TerritoryID="3"]
```
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).
The following is a partial result:
```
...
...
...
...
```
### C. Specify a top-level predicate
The following query returns the **\** child element nodes of the context node that have **\** element children. The query tests the location path as the top-level predicate:
```
/child::Customer[child::Order]
```
The **child** axis is the default. Therefore, the query can be specified as:
```
/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 (TopLevelPredicate.xml) and save it in the directory where SampleSchema1.xml is saved.
```
/Customer[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:
```
...
...
...
...
```