Avatar of soozh
soozh
Flag for Sweden asked on

TSQL to export data in XML format

Hello,

Using MS SQL Server 2008.

I have been asked to create an XML document by exporting data from a database.

I have been given an XSD defining the data to be exported.

I know where the data is held in the database.

What would be the best approach to generating the file?  It will contain many "rows" of data.

Thanks.
Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Saurabh Bhadauria

8/22/2022 - Mon
Saurabh Bhadauria

if you looking for how to do it in SQL server ..there are three option...

Through SSIS
Uisng BCP
Uisng SQL CMD

You can get plenty of example on Google.... other wise further let me know your thoughts....


Thanks,
Saurabh
soozh

ASKER
THanks for the response.  I think i will have to use SQL CMD.

Are there recommend methods/techniques to use?

/richard
Saurabh Bhadauria

Get some idea from here
http://msdn.microsoft.com/en-IN/library/ms162773.aspx

Consider below example for xml export

EXECUTE master..xp_cmdshell 'SqlCmd   -S SAURABHBHADURIA -d master  -E  -i d:\query.sql  -h -1 -y 0   -o d:\out.xml '



in d:\query.sql File I have save my query ..which is below..

 set nocount on
:XML ON
  SELECT top(50) name,type FROM master.sys.objects s for xml Raw ,elements , ROOT ('EMSExport')

Thanks,
Saurabh
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Saurabh Bhadauria

Also check your xml output format....
You can get the desired format   by changing the Query...using for xml clause
soozh

ASKER
i have seen that its possible to use an XSD to validate the output, and XSD to define where the data is to be collected from.

Is it possible to combine these two somehow in one query?
ASKER CERTIFIED SOLUTION
Saurabh Bhadauria

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question