I have a sql 2005 db used to archive hundreds of csv files that i store in a varchar(max) field. I've written a sproc to get a csv out again to the file system using the following code:
SET @cmd = 'bcp "SELECT Document FROM CSV_Archive.dbo.DocStore WHERE DocID ='+ CAST(@DocID AS VARCHAR)+'" queryout '+@oFile+' -S -T -N';
EXEC master..xp_cmdshell @cmd;
The resulting file contains some additional characters at the begining of the file - like so:
Ü‚NUL NUL NUL NUL NUL NUL.
Then the rest of the file is as it should be.
Any idea how I can avoid getting these unwanted extra characters?