Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exporting xml from sql server

Status
Not open for further replies.

hatemgamil

Programmer
Mar 18, 2010
41
Greetings

lets say i have a table Employee like this

EmpID,EmpName
1 ,hatem

and i write a query that select * from Employee for xml auto

so the out put will be in xml format

i want some help to know how can i export the result to a xml file to be saved on my computer as i need to read the .xmls files from this folder and deserialize them in my .net application

thnx
 
You may want to look at the bcp utility. It may be used to bulk import data into a table or export data from a table to a file. Now, I have never used it with FOR XML...Try. And I believe the file gets created on the server' s HD...not sure, but check it out.

Good luck.

MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
 
thnx bugslayer

can u please give me more details about bcp

i mean an example

thnx
 
Hi. Unfortunately not much time right now, but you may look at the links below:

In it' s simplest form, to export data from a table to a data file for instance:
Code:
bcp "SELECT FirstName, LastName FROM AdventureWorks2008R2.Person.Person ORDER BY LastName, Firstname" queryout Contacts.txt -c -T

You would type that at a command prompt, or in SSMS, or save it in a command file and execute the file. In the example the -c switch means the data will be exported in the CHAR datatype and -T means BCP (bulk copy) utility connects to SQL Server using a trusted connection. So what I am saying is that maybe for XML you would have something like:
Code:
bcp "SELECT FirstName, LastName FROM AdventureWorks2008R2.Person.Person ORDER BY LastName, Firstname FOR XML AUTO" queryout Contacts.txt -c -T
probably with some formatting, but I have not had the chance to test it. I know FOR XML will produce one long line with the XML in it...Maybe your .NET code can parse it.

Let me know what you find out.

Good luck.

MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
 
George,

Looks like the url was truncated. Can you post again? I am inerested to read the article. Thanks
 
It looks like TT is losing the last character, which happens to be a dash. Weird. If you click the link and add a dash at the end of the url, it works. This should also work.


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top