--- title: "String Search in XQuery | Microsoft Docs" description: Learn how to search text in XML documents by viewing an example of string search in XQuery. ms.custom: "" ms.date: "03/04/2017" ms.prod: sql ms.prod_service: sql ms.reviewer: "" ms.technology: xml ms.topic: "language-reference" dev_langs: - "XML" helpviewer_keywords: - "strings [SQL Server], search" - "XML [SQL Server], searching text" - "searches [SQL Server], XML documents" - "XQuery, string search" ms.assetid: edc62024-4c4c-4970-b5fa-2e54a5aca631 author: "rothja" ms.author: "jroth" --- # String Search in XQuery [!INCLUDE[tsql-appliesto-ss2012-xxxx-xxxx-xxx-md](../includes/tsql-appliesto-ss2012-xxxx-xxxx-xxx-md.md)] This topic provides sample queries that show how to search text in XML documents. ## Examples ### A. Find feature descriptions that contain the word "maintenance" in the product catalog ``` SELECT CatalogDescription.query(' declare namespace p1="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; for $f in /p1:ProductDescription/p1:Features/* where contains(string($f), "maintenance") return $f ') as Result FROM Production.ProductModel WHERE ProductModelID=19 ``` In the previous query, the `where` in the FLOWR expression filters the result of the `for` expression and returns only elements that satisfy the **contains()** condition. This is the result: ``` 10 maintenance contact available through your dealer or any AdventureWorks retail store. ``` ## See Also [XML Data (SQL Server)](../relational-databases/xml/xml-data-sql-server.md) [XQuery Language Reference (SQL Server)](../xquery/xquery-language-reference-sql-server.md)