In SQL Server, when we use FOR XML
to return query results in an XML document, the resulting XML document is returned as a string by default. However, we can change this so that it’s returned in the xml data type.
To do this, all we need to do is append our query with the TYPE
directive.