How to display the XML result of 'Select For XML Explicit'
I'm using the For XML Explicit statement in a stored procedure. I would like to see the full result set, but only get a partial result set in the Query Analyzer result window. Is there an easy way to display the XML result or save it to a file so I can verify whether the resulting XML is well formed for the eventual user of this output?
The output of Select For XML Explicit can be voluminous. SQL Query analyzer doesn't do a great job of presenting the output of For XML queries. For the best results use the menu command Tools -> Options. On the Results tab change the "Maximum characters per column" to 8192. Then use the menu command Query -> Result in Text (Ctrl+T). These options give you the best XML output from Query Analyzer.
Even better than Query Analyzer's output is a utility that I wrote to allow experimentation with For XML queries as Appendix C of the book SQL Server 2000 XML Distilled. The code is in the book's download. The original version of the utility is in Visual Basic 6. I've also written a C# version of the utility, which is available on my Web site.
Do you have comments on this Ask the Expert Q&A? Let us know.
This was first published in May 2005