Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 1.29 KB

example-renaming-the-row-element.md

File metadata and controls

41 lines (33 loc) · 1.29 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic helpviewer_keywords
Example: Renaming the <row> Element
View an example of renaming an XML row element by specifying an optional argument to RAW mode in the FOR XML clause.
MikeRayMSFT
mikeray
randolphwest
05/05/2022
sql
xml
conceptual
RAW mode, renaming <row> example

Example: Rename the <row> element

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]

For each row in the result set, the RAW mode generates an element <row>. You can optionally specify another name for this element by specifying an optional argument to the RAW mode, as shown in this query. The query returns a <ProductModel> element for each row in the rowset.

Example

SELECT ProductModelID, Name
FROM Production.ProductModel
WHERE ProductModelID = 122
FOR XML RAW ('ProductModel'), ELEMENTS;
GO

This is the result. Because the ELEMENTS directive is added in the query, the result is element-centric.

<ProductModel>
  <ProductModelID>122</ProductModelID>
  <Name>All-Purpose Bike Stand</Name>
</ProductModel>

See also