title: Append output of sqlcmd to file using Job Agent
body: <p>After some research I found the solution to append the output of a sqlcmd command to a csv file. Everything is fine when using the Command Shell:</p>
  
  <pre><code>C:\temp&gt;sqlcmd -S &lt;SERVER&gt; -d &lt;DATABASE&gt; -E -Q "SELECT [something] FROM [TableX] WHERE [columnY] IS NOT NULL;" -W -h-1 -s";" &gt;&gt;"&lt;FULL_PATH_TO_CSV-FILE&gt;"
  </code></pre>
  
  <p>I want to schedule this stuff by using SQL Server Job Agent (with same account as with console) so I add a Job (type CmdExec). Job execution fails with the following error (unexpected argument):</p>
  
  <blockquote>
    <p>Meldung
    Ausgeführt als Benutzer: ''[ACCOUNT]''. Sqlcmd: '>>''[FULL_PATH_TO_CSV-FILE]'': Unerwartetes Argument. Geben Sie '-?' ein, um die Hilfe anzuzeigen.  Prozessexitcode 1.  Fehler bei Schritt.</p>
  </blockquote>
  
  <p>My workaround works fine: remove <code>&gt;&gt;"&lt;FULL_PATH_TO_CSV-FILE&gt;"</code> and use the output file of the step. But: I want to use the output file for logging purposes - not for the data output ...</p>
  
  <p>The question is: why does the ">>" command does not work within a SQL Server Agent job?</p>
  
  <p>I don't want to simply redirect the output. I know that sqlcmd provides the parameter <code>-o</code> for that. In this case an existing file would be overwritten. That's not what I want.</p>
  
  <p>Unfortunatelly I do not have the reputation to post the screenshots so far.</p>
  
  <p>Thanks you very much in advance!</p>
  
  <p>Best regards,
  D.C.</p>