From the course: SQL Server 2014 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Writing queries to return XML

Writing queries to return XML - SQL Server Tutorial

From the course: SQL Server 2014 Essential Training

Start my 1-month free trial

Writing queries to return XML

- In this section, we're going to look at some tools and techniques, for returning XML formatted data, from SQL Server. So we'll start with a basic SELECT statement, very similar to ones that we've used in previous exercises. Where we're just selecting four columns from the HumanResources.Employee table. And if we execute that, we see the data returned to us in tabular format. Tabular format meaning rows and columns. If we would like this exact same data returned to us in XML format, instead of tabular format, we just need to add three little keywords at the end of the select statement. So I'm going to add FOR XML RAW. Three separate words, a space in between each. Then I'll execute this again, and at first we just see a little snip of the XML. If we click on that, we'll get the full document. And we see that its the exact same data as before, just now formatted as XML. What was a row in the tabular format is now a line of XML. And all of the columns have been turned into XML…

Contents