title: SQLCMD command, How to save output into log file
body: <p>The following question has helped me solving the problem of executing multiple SQL Scripts located in file. <a href="https://stackoverflow.com/questions/2583517/run-all-sql-files-in-a-directory">Run all SQL files in a directory
  </a>
  However, I did not get how to redirect the output into a separate log file. Someone suggested the following script but since I don't understand it, it did not work and I can't find out the error. </p>
  
  <pre><code>for %f in (*.sql) do sqlcmd /S &lt;servername&gt; /d &lt;dbname&gt; /E /i "%f" &gt;&gt; sql.log 2&gt;&amp;1) 
  </code></pre>