O'Reilly logo

SQL Server Advanced Data Types: JSON, XML, and Beyond by Peter A. Carter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Peter A. Carter  2018
Peter A. CarterSQL Server Advanced Data Typeshttps://doi.org/10.1007/978-1-4842-3901-8_3

3. Constructing XML with T-SQL

Peter A. Carter1 
(1)
London, UK
 

T-SQL allows you to convert relational results sets into XML, by using the FOR XML clause in your SELECT statement. There are four modes that can be used with the FOR XML clause; FOR XML RAW, FOR XML AUTO, FOR XML PATH, and FOR XML EXPLICIT. This chapter will demonstrate how the FOR XML clause works in RAW mode, AUTO mode, PATH mode, and EXPLICIT mode. As the chapter progresses, we will move from simple to more complex examples.

Using FOR XML RAW

The simplest and easiest to understand of the FOR XML modes is FOR XML RAW. This mode will transform each row in a relational result ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required