title: SQLCMD in a for loop
body: <p>I have recently discovered that i am not able to fire the following command from a batch file:</p>
  
  <pre><code>for %%G in (%path%) do sqlcmd /S &lt;my-server&gt; /d &lt;my-database&gt; /E /i "%%G" -b
  </code></pre>
  
  <p>It tells me, that it could not find the command "sqlcmd". However, if I run this command directly in the command prompt (by removing one % of each pair) it works!</p>
  
  <p>Why is that and how can I make it work with my batch file?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>This is the following code I got in my batch file:</p>
  
  <pre><code>@echo off
  set mypath=%~dp0
  set mypath=%mypath%sql
  
  for %%G in ("%mypath%") do echo %%G &amp; sqlcmd /S sample-server /d sample-database /E /i "%%G" -b
  
  pause
  </code></pre>