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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL to XML

Author  Topic 

derach2000
Starting Member

37 Posts

Posted - 2010-04-27 : 04:37:14
Hi, I was wondering is there a way to directly save the result of an query to a XML file on the disk.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-27 : 04:41:09
Yup.use FOR XML clause and use bcp to store it in file

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-27 : 04:51:12
see example here

http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sathiesh2005
Yak Posting Veteran

85 Posts

Posted - 2010-04-27 : 05:50:05
Hi,
Code here.

DECLARE @ExecCmd VARCHAR(3000)
SET @ExecCmd='bcp "SELECT COL1,COL2,COL3,...COLn FROM table FOR XML AUTO,ELEMENTS" queryout d:\FileName.xml -w -r "" -S 102.87.10.10 -U user -P pwd'
EXEC master..xp_cmdshell @ExecCmd


Regards,
Sathieshkumar. R
Go to Top of Page
   

- Advertisement -