title: SQL Server: removing line breaks when exporting data to csv file using Bulk export utility
body: <p>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 <a href="https://docs.microsoft.com/it-it/sql/tools/bcp-utility?view=sql-server-2017" rel="nofollow noreferrer">bcp utility</a> to export data from Sql Server to the csv file.</p>
  
  <p>This is the strucutre of the table:</p>
  
  <pre><code>ID int
  CODE varchar(20)
  XML_DATA xml
  </code></pre>
  
  <p>This is the command I am using:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>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):</p>
  
  <pre><code>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
  </code></pre>
  
  <p>What am I missing here? </p>