I have a table which I need to export to a csv file. This table has an xml field which can have line breaks that I must remove. I am using the bcp utility to export data from Sql Server to the csv file.
This is the strucutre of the table:
ID int
CODE varchar(20)
XML_DATA xml
This is the command I am using:
bcp "SELECT ID, CODE, replace(convert(nvarchar(max), XML_DATA), CHAR(13)+CHAR(10), ' ') as XML_DATA FROM MYDB.dbo.MyTable" queryout C:\output.csv -c -t0x1F -T -S "10.10.10.28"
For some reasons the output file still contains the line breaks. But if I run the same query on SQL Server for a record which has a line break, the output is correct (line breaks removed):
SELECT
ID,
CODE,
replace(convert(nvarchar(max), XML_DATA), CHAR(13)+CHAR(10), ' ') as XML_DATA
FROM MYDB.dbo.MyTable
WHERE ID = 1099; -- record with a line break in the XML_DATA field
What am I missing here?