The FOR XML clause has four of the most basic patterns
1. Auto mode: Returns the data table as the element of the table name, the value of each column is returned as a property;
2. Raw mode: Returns the data behavior element, the value of each column as the attribute of the element;
3. Path mode: Allows users to customize nested XML structures, elements, attribute values through simple XPath syntax
4. Explicit mode: Defines the structure of the output XML through the SELECT syntax
The query result set is presented in XML, simplifying query statements to implement some of the work that might have previously been done with the help of a function stored procedure
Select * fromBasetype_bty forXML AutoSelect * fromBasetype_bty forXmlRawSelect * fromBasetype_bty forXmlRaw, ElementsSelect * fromBasetype_bty forXmlRaw, Elements XsinilSELECT * fromBasetype_bty forXML PATH--the custom name is <myhobby>SELECT * fromBasetype_bty forXML PATH ('Myhobby')
SQL Server FOR XML