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 ...