Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 2.66 KB

File metadata and controls

48 lines (39 loc) · 2.66 KB
title Use PATH Mode with FOR XML
description Learn how to use PATH mode with nested FOR XML queries and the TYPE directive to write less complex queries that return xml type instances.
author MikeRayMSFT
ms.author mikeray
ms.reviewer randolphwest
ms.date 05/09/2024
ms.service sql
ms.subservice xml
ms.topic concept-article
ms.custom
ignite-2025
helpviewer_keywords
PATH FOR XML mode
characters [SQL Server], XML
aliases [SQL Server], XML
FOR XML clause, PATH mode
FOR XML PATH mode
column names [SQL Server]
XPath queries [SQL Server]

Use PATH mode with FOR XML

[!INCLUDE SQL Server Azure SQL Database FabricSQLDB]

As described in FOR XML (SQL Server), the PATH mode provides a simpler way to mix elements and attributes. PATH mode is also a simpler way to introduce more nesting for representing complex properties. You can use FOR XML EXPLICIT mode queries to construct such XML from a rowset, but the PATH mode provides a simpler alternative to the potentially cumbersome EXPLICIT mode queries. PATH mode, together with the ability to write nested FOR XML queries and the TYPE directive to return xml type instances, allows you to write queries with less complexity.

In PATH mode, column names or column aliases are treated as XPath expressions. These expressions indicate how the values are being mapped to XML. Each XPath expression is a relative XPath that provides the item type. Types include the attribute, element, scalar value, and the name and hierarchy of the node that is generated, relative to the row element.

This section describes mapping columns in a rowset under various conditions, and provides examples.

In this section

Related content