Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 exporting to xml with sqlexpress
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

36 Posts

Posted - 10/05/2012 :  14:52:01  Show Profile  Reply with Quote
I'm using Sql Server Management Studio 2008 for SqlExpress,

does it have a way to export data to a file in xml format?

Thanks in advance for your time

Rafael Soteldo

Edited by - rafael.soteldo on 10/05/2012 14:54:10

Most Valuable Yak

15732 Posts

Posted - 10/05/2012 :  15:10:08  Show Profile  Visit robvolk's Homepage  Reply with Quote
Yes, you can use the FOR XML clause of a SELECT statement to format the output as XML, then use the bcp utility to create a file:
bcp "select top 10 * from master..spt_values val for xml auto, root('vals')" queryout xml.txt -Sserver -T -w
That query will generate the following XML:
<val name="rpc" number="1" type="A  " status="0"/>
<val name="pub" number="2" type="A  " status="0"/>
<val name="sub" number="4" type="A  " status="0"/>
<val name="dist" number="8" type="A  " status="0"/>
<val name="dpub" number="16" type="A  " status="0"/>
<val name="rpc out" number="64" type="A  " status="0"/>
<val name="data access" number="128" type="A  " status="0"/>
<val name="collation compatible" number="256" type="A  " status="0"/>
<val name="system" number="512" type="A  " status="0"/>
<val name="use remote collation" number="1024" type="A  " status="0"/>
I'm pretty sure the bcp utility is installed with SQL Express, if not you can download it separately. Be sure to use the -w parameter to save the file as Unicode rather than ANSI text, XML is a Unicode format.
Go to Top of Page

Starting Member

36 Posts

Posted - 10/05/2012 :  20:28:19  Show Profile  Reply with Quote
Thank you

I'll try it

Thanks in advance for your time

Rafael Soteldo
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000