title: Run all SQL files in multiple directories
body: <p>I combined a couple of solutions I found online to try and make this happen.</p>
  
  <p><a href="https://stackoverflow.com/a/6504317/2471473">https://stackoverflow.com/a/6504317/2471473</a></p>
  
  <p><a href="https://sqlandme.com/2013/03/25/sql-server-executing-multiple-script-files-using-sqlcmd/" rel="nofollow noreferrer">https://sqlandme.com/2013/03/25/sql-server-executing-multiple-script-files-using-sqlcmd/</a></p>
  
  <p>I'm trying to run a single .cmd script (Script1.cmd) with folder locations of .sql files. That single script runs another script (Script2.cmd) to use sqlcmd to execute all the .sql files in that folder location.  It mostly works, but it leaves a command window open that I have to exit from for each folder location.</p>
  
  <p>Script1.cmd</p>
  
  <pre><code>start Script2.cmd "C:\Location1"
  start Script2.cmd "C:\Location2"
  </code></pre>
  
  <p>Script2.cmd</p>
  
  <pre><code>@Echo Off
  FOR /f %%i IN ('DIR %1\*.Sql /B') do call :RunScript %1 %%i
  GOTO :END
  
  :RunScript
  Echo Executing Script: %2
  cd %1
  SQLCMD -S Server123 -d Database456 -E -i %2
  Echo Completed Script: %2
  
  :END
  </code></pre>