title: I am trying to check if a database exists using sqlcmd.exe via batch command and will do other things based on the result
body: <p>I am writing a batch file that checks the existence of a database, and based on the outcome batch will execute other statements.</p>
  
  <pre><code>FOR /F "usebackq" %%S IN ( `sqlcmd.exe -S %server% -d master -U %username% -P !password! ^
      -Q "set nocount on; select count(*) from dbo.sysdatabases where [name]='$(inputDatabase)'" -v inputDatabase="%databaseName%"` ) DO (
   SET existsDB=%%S
   )
  if !existsDB! EQU 1 (
      REM DO SOMETHING
  ) else (
      REM DO SOMETHING
  )
  </code></pre>
  
  <p>Dynamic assignment of database name fails. Returns the "Sqlcmd: 'TestDB': Invalid argument. Enter '-?' for help."</p>
  
  <p>I would appreciate any directions to solve the issue.</p>