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

2. Building XML

Alex Grinberg1 
(1)
Richboro, Pennsylvania, USA
 

XML is represented in SQL Server using a complex data type that has special syntax and well-defined format. It can be used when we need to construct XML-formatted output or shred existing XML into relational format. In this chapter I will provide recipes for building XML from a result set based on one or more tables, and for formatting and presenting the result as XML output.

Introduced in SQL Server 2000, the FOR XML clause has evolved dramatically to become a comprehensive solution for building XML output. FOR XML has to be the last clause in a SELECT statement and has to ...

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.