title: Return value of SQLCMD
body: <p>I need to check the exit status (success/failure) of a query run through SQLCMD utility. For example, the server I am connecting <em>doesn't</em> have a database name <code>EastWind</code>. Then, the command below fails with the message ...</p>
  
  <pre><code>&gt; "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" 
       -S ZEPHIR -E -Q "USE WestWind"
  Changed database context to 'WestWind'.
  &gt; echo %errorlevel%
  0
  &gt; "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" 
       -S ZEPHIR -E -Q "USE EastWind"
  Database 'EastWind' does not exist. Make sure that the name is entered correctly
  &gt; echo %errorlevel%
  0
  </code></pre>
  
  <p>I see that the return value is the same in both the cases. How can I check if a command has failed in <code>SQLCMD</code>?</p>