©  Alex Grinberg 2018
Alex GrinbergXML and JSON Recipes for SQL Serverhttps://doi.org/10.1007/978-1-4842-3117-3_6

6. Filtering XML

Alex Grinberg1 
(1)
Richboro, Pennsylvania, USA
 

The filtering mechanism for XQuery has some differences and specifications when compared to the T-SQL WHERE clause. In my experience, when DBAs and Developers implement filters for XQuery, it is mostly based on a T-SQL strategy or to create dynamic SQL that is not efficient and could be very difficult to maintain, especially when the filter is implemented as dynamic SQL. This chapter will demonstrate many examples of how to implement filters for XQuery requests.

6-1. Implementing the exist( ) Method

Problem

You want to determine whether a specific element or attribute exists ...

Get XML and JSON Recipes for SQL Server: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.