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
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Trivial example of XML output from SQLCMD

Author  Topic 

PhilipLewis
Starting Member

30 Posts

Posted - 2013-10-14 : 15:30:14
I am trying to get SQLCMD to execute a stored procedure which outputs XML to a named file

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


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
:XML ON
-S "MYNODE" -E -Q "set nocount on; execute [MyDB].[dbo].[aaa]" -o C:\temp\aaa.xml
:EXIT


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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-14 : 16:36:15
Try it like this:
sqlcmd -S "MYNODE"
>:XML ON
>set nocount on; execute [MyDB].[dbo].[aaa]" -o C:\temp\aaa.xml
>GO
>EXIT
Go to Top of Page
   

- Advertisement -