Export SQL Server 2005 Xml Column Data to Xml File

Xml data stored using the SQL Server 2005 xml data type can be exported a number of ways and you can obviously write a managed stored procedure to do it.

However for a quick, one off, type approach you can use the BCP command.

bcp "SELECT [xml column name] FROM [TableName] FOR XML RAW"
      queryout c:\myOutputData.xml -SServerName -T -w -r -t

The downside of this is that, given the command above you’ll get your xml row data exported as shown;

{row 1 xml}
{row 2 xml}

so you might need to do some mangling on the output file, or you can obviously change the initial SELECT statement to shape your output appropriately.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.