SQL Server FOR XML AUTO Examples

In SQL Server, the FOR XML clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML clause at the end of the query will output the results in XML.

When we do this, we have the option of specifying RAW, AUTO, EXPLICIT, or PATH mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.

Below are examples of using AUTO mode when generating XML from a SQL query.

Continue reading

SQL Server FOR XML PATH Examples

In SQL Server, the FOR XML clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML clause at the end of the query will output the results in XML.

When we do this, we have the option of specifying RAW, AUTO, EXPLICIT, or PATH mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.

Below are examples of using PATH mode when generating XML from a SQL query.

Continue reading

Fix Msg 529 “Explicit conversion from data type int to xml is not allowed” in SQL Server

If you’re getting SQL Server error Msg 529 that reads something like Explicit conversion from data type int to xml is not allowed, it’s probably because you’re trying to perform a data type conversion that’s not permitted.

SQL Server doesn’t allow certain conversions. If you try to perform such a conversion, you’ll get this error.

Continue reading

What is STATISTICS XML in SQL Server?

In SQL Server, you can use the SET STATISTICS XML statement to generate detailed information about how a T-SQL statement was executed.

This information is provided in the form of a well formed XML document.

Once SET STATISTICS XML is set to ON, each subsequent statement is reflected in the output by a single XML document.

Each XML document contains the text of the statement, followed by the details of the execution steps.

The output shows run-time information such as the costs, accessed indexes, and types of operations performed, join order, the number of times a physical operation is performed, the number of rows each physical operator produced, and more.

Continue reading

How SHOWPLAN_XML Works in SQL Server

In SQL Server, you can use the SET SHOWPLAN_XML statement to return detailed information about how a T-SQL statement will be executed, in the form of a well-defined XML document.

It’s similar to SHOWPLAN_ALL, except that SHOWPLAN_ALL returns its data set of rows that form a hierarchical tree.

You can set SHOWPLAN_XML to either ON or OFF.

When SHOWPLAN_XML is ON, all subsequent T-SQL statements are not executed. Instead SQL Server returns execution information for the statement (without executing it).

Continue reading