title: BCP Adds Space In Output
body: <p>This BCP Statement is adding a space between my data.  See image
  <a href="https://i.stack.imgur.com/ZQwdm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQwdm.png" alt="Issue"></a></p>
  
  <p>This is DDL and sample data - what do I need to change so that the space is not added?  (Empty column)</p>
  
  <pre><code>Declare @TestMe Table
  (
  field1 varchar(20),
  field2 varchar(20),
  field3 varchar(20),
  field4 varchar(20),
  field5 varchar(20),
  field6 varchar(20),
  field7 varchar(20),
  field8 varchar(20),
  field9 varchar(20),
  field10 varchar(20),
  field11 varchar(20),
  field12 varchar(20),
  field13 varchar(20),
  field14 varchar(20),
  field15 varchar(20),
  field16 varchar(20),
  field17 varchar(20)
  )
  
  Insert Into @TestMe Values
  ('Blue', 'Red', NULL, NULL, NULL, NULL, 'Seven', 'Eight', NULL, NULL, Null, Null, 'Pink', 'Orange', 'NFL', 'Size', 'Last')
  
  Declare @field1 varchar(20),@sql nvarchar(4000), @filename varchar(100)
  Set @field1 = 'Blue'
  Set @filename = 'C:\Test.csv'
  Set @sql = 'bcp "SELECT ''one'',''two'',''three'',''four'',''five'',''six'',''seven'',''eight'',''nine'',''ten'',''eleven'',''twelve'',''thirteen'',''fourteen'',''fifteen'',''sixteen'',''seventeen'' UNION ALL SELECT CHAR(34)+CONVERT(varchar(10),[field1],101)+CHAR(34),CHAR(34)+CAST([field2] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field3] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field4] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field5] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field6] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field7] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field8] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field9] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field10] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field11] As VARCHAR(MAX))+CHAR(34),CHAR(34) + CAST([field12] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field13] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field14] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field15] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([inventorycode] As VARCHAR(MAX))+CHAR(34),CHAR(34)+CAST([field16] As VARCHAR(MAX))+CHAR(34) FROM [@TestMe] WHERE field1 = '''+@field1+'''" queryout "'
  SET @sql = @sql + @filename + '" -c -t, -T -S '+@@SERVERNAME
  exec master..xp_cmdshell @sql
  </code></pre>