title: BOM at start of file when using spWriteStringToFile in SQL Server
body: <p>I'm using SQL server to export data from a query in both HTML and CSV format. I also write out a batch file which calls CoreFTP to SFTP these files to a site. There is a nightly process that calls the batch file and SFTP these files. Everything has the potential to work except that the batch file has a BOM (byte order mark) at the start which cmd.exe chokes on. At least I think that is what it is.</p>
  
  <p>When the batch file executes the error is '{unprintable character}C' is not recognized as an internal or external command. The unprintable character does not show in a text editor, but it is there. I think it has something to do with UTF encoding.</p>
  
  <p>Is there a way to change the encoding when using spWriteStringToFile?</p>
  
  <p>Greg</p>
  
  <pre><code>DECLARE @CoreFileName VARCHAR(30)
  SET @CoreFileName = CONVERT(VARCHAR(10), CURRENT_TIMESTAMP, 105)
  
  DECLARE @FileName VARCHAR(30)
  
  SET @FileName = 'ED_' + @FileName 
  
  SET @FileName = CONVERT(VARCHAR(10), CURRENT_TIMESTAMP, 105) + '.html'
  EXEC spWriteStringToFile @OutPut, 'D:\OutFolder\FTP\', @FileName 
  
  SET @FileName = CONVERT(VARCHAR(10), CURRENT_TIMESTAMP, 105) + '.csv'
  EXEC spWriteStringToFile @CSVOutPut, 'D:\OutFolder\FTP\', @FileName 
  
  DECLARE @CoreFTP VARCHAR(200)
  SET @CoreFTP = 'C:' + CHAR(13) + CHAR(10) + 'cd "C:\Program Files\CoreFTP\"' + CHAR(13) + CHAR(10) 
  
  SET @CoreFTP = @CoreFTP + 'coreftp.exe -site OpenDoor -B -u D:\OutFolder\' + @CoreFileName + '.* /NCHIN/InpatientNotice/'
  EXEC spWriteStringToFile @CoreFTP, 'D:\OutFolder\', 'SendFiles.Bat'
  </code></pre>