Problem solve Get help with specific problems with your technologies, process and projects.

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 last published in May 2005

Dig Deeper on XML in SQL Server

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.