title: SQLCMD, command-line variables and script :setvar
body: <p>When running SQLCMD.exe and providing command-line arguments for scripting variables, I expect that the values provided on the command-line will override those defined in the SQL script file.</p>
  
  <p>e.g.</p>
  
  <p>Given the following SQL Script:</p>
  
  <pre><code>:setvar XXX "SQL script"
  print '$(XXX)'
  </code></pre>
  
  <p>And the command line:</p>
  
  <pre><code>sqlcmd.exe -S &lt;Server&gt; -d &lt;Database&gt; -E -b -i &lt;Script&gt; -v XXX="Batch script"
  </code></pre>
  
  <p>I expect the output to be:</p>
  
  <blockquote>
    <p>Batch script</p>
  </blockquote>
  
  <p>However the output is:</p>
  
  <blockquote>
    <p>SQL script</p>
  </blockquote>
  
  <p>Is this the intention, or must the <code>:setvar</code> statements in the SQL script be removed?</p>
  
  <p>I provided the <code>:setvar</code> statements in script, so I can edit/test the script in SQL Management Studio with SQLCMD mode, but run the scripts from the command-line in my test and production environments.</p>