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)
 BCP export to XML issue

Author  Topic 

Cooper_32
Starting Member

3 Posts

Posted - 2014-05-15 : 10:41:50
Hi

I am having some problems exporting an XML file via BCP.
I have created a stored procedure that creates the XML file, complete with the version declaration <?xml version="1.0" encoding="utf-8" ?>.

If I run the procedure manually through sql management studio it correctly creates the file complete with the declaration and saves it to my local path.

However when I run it through BCP, it strips off the declaration.
Can anyone assist with the correct BCP options, or suggest an alternative.


BCP code below
**************

Set @BcpCommand = 'BCP ' + @BcpSqlQuery + ' queryout "' + @FileLocation+'\'+@FileName + '" -w -S'+@InstanceName+' -Usa -Psa'
exec xp_cmdshell @BcpCommand, 'NO_OUTPUT'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-15 : 12:20:36
Show us the output of this: PRINT @BcpCommand

Maybe you need to add -c and -r\r\n?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Cooper_32
Starting Member

3 Posts

Posted - 2014-05-15 : 14:20:30
Hi

Here is the printout, as requested

BCP exec.Benson.dbo.UDEF_SP_XML_DIM_ORDERS_OUT queryout "C:\Upload\OrderUpload.xml" -w -x -SDM6S9W1\SQL2008R2 -Usa -Psa

I should add however, that I posted this to the wrong forum, as it's
SQL 2008 not 2000
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-15 : 15:02:35
quote:
Originally posted by Cooper_32


I should add however, that I posted this to the wrong forum, as it's
SQL 2008 not 2000



I moved the topic to a 2008 forum.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-15 : 15:03:41
Did you try adding the -c parameter?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Cooper_32
Starting Member

3 Posts

Posted - 2014-05-15 : 16:38:48
I did but it hasn't made any difference.
Do the options have to be in a set order?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-15 : 16:59:00
After the file path/name, no.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -