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

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

rafael.soteldo
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

robvolk
Most Valuable Yak

USA
15671 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:
<vals>
<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"/>
</vals>
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

rafael.soteldo
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  
 New 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.11 seconds. Powered By: Snitz Forums 2000