--- title: "Specifying Relational Operators 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], relational operators" - "relational operators [SQLXML]" - "XPath operators [SQLXML]" - "operators [SQLXML]" ms.assetid: 177a0eb2-11ef-4459-a317-485a433ee769 caps.latest.revision: 25 author: "douglaslMS" ms.author: "douglasl" manager: "jhubbard" --- # Specifying Relational Operators in XPath Queries (SQLXML 4.0) The following examples show how relational operators 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 relational operator This XPath query returns the child elements of the **\** element where the **CustomerID** attribute value is "1" and where any child **\** elements contain an **\** child with a **OrderQty** attribute with a value greater than 3: ``` /child::Customer[@CustomerID="1"]/Order/OrderDetail[@OrderQty > 3] ``` The predicate specified in the brackets filters the **\** elements. Only the **\** elements that have at least one **\** grandchild with a OrderQty attribute value greater than 3 are returned. The **child** axis is the default. Therefore, the query can be specified as: ``` /Customer[@CustomerID="1"]/Order/OrderDetail[@OrderQty > 3] ``` ##### 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 (SpecifyRelationalA.xml) and save it in the directory where SampleSchema1.xml is saved. ``` /Customer[@CustomerID="1"]/Order/OrderDetail[@OrderQty > 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). Here is the result set of the template execution: ``` ``` ### B. Specify relational operator in the XPath query and use Boolean function to compare the result This query returns all the **\** element children of the context node that have an **SalesPersonID** attribute value that is less than 270: ``` /child::Customer/child::Order[(attribute::SalesPersonID < 270)=true()] ``` 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/Order[(@SalesPersonID < 270)=true()] ``` > [!NOTE] > When this query is specified in a template, the < character must be entity encoded because the < character has special meaning in an XML document. In a template, use `<` to specify the < character. ##### 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 (SpecifyRelationalB.xml) and save it in the directory where SampleSchema1.xml is saved. ``` /Customer/Order[(@SalesPersonID<270)=true()] ``` 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: ``` ... ```