I know using ">>" in a DOS command one can append data to a file.
Code: Select all
DECLARE @ExportSQL nvarchar(max); SET @ExportSQL = N'EXEC master.dbo.xp_cmdshell ''bcp "SELECT * FROM MyDatabase.dbo.MyTable WHERE FileName = ''''' + @FileName + '''''" queryout "' + @OutputFilePath + '\OutputData.csv" -T -c -t, -S ServerName'''
EXEC(@ExportSQL)