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
 SSIS and Import/Export (2008)
 Trivial example of XML output from SQLCMD
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

30 Posts

Posted - 10/14/2013 :  15:30:14  Show Profile  Reply with Quote
I am trying to get SQLCMD to execute a stored procedure which outputs XML to a named file

create procedure [dbo].[aaa]
select top 1 * from dbo.MyTable for xml auto, elements

This works when executed from SSMS. Output to text returns a heading line and underline, followed by the appropriate XML output.

I tried this command from the CLI

C:> sqlcmd
-S "MYNODE" -E -Q "set nocount on; execute [MyDB].[dbo].[aaa]" -o C:\temp\aaa.xml

It returns the heading line and underline, followed by a very long string of what appear to be concatenated HEX numbers
I tried this on various major versions with the same results.

Despite the fact that I have made an attempt to read the manual, obviously I am still doing something totally wrong.
The ":XML ON" command has no apparent effect.

A clue or two would be appreciated.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 10/14/2013 :  16:36:15  Show Profile  Reply with Quote
Try it like this:
sqlcmd -S "MYNODE"
>set nocount on; execute [MyDB].[dbo].[aaa]" -o C:\temp\aaa.xml
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.09 seconds. Powered By: Snitz Forums 2000