title: USE DB that may not exist
body: <p>I have a script that has a <code>USE DATABASE</code> statement.
  The script runs perfectly fine if the database exists. If it doesn't exist, it fails with the message "the database doesn't exist", which makes perfect sense. </p>
  
  <p>Now, I don't it to fail so I added a check to select if the DB exists on sys.databases (which I will represent here with a <code>IF 1=2</code> check for the sake of simplicity), so, if the DB exists (1=1), then run the "use" statement.</p>
  
  <p>To my surprise, the script kept failing. So I tried to add a TRY CATCH block. Same result. 
  It seems that the use statement is evaluated prior to anything else, which id quite annoying because now my script may break. </p>
  
  <p>So my question is: how can I have an <code>use</code> statement on a script to a database that may not exist?</p>
  
  <pre><code>BEGIN TRY
     IF (1=1) BEGIN --if DB exists
      USE DB_THAT_MAY_NOT_EXIST
     END 
  END TRY
  BEGIN CATCH
  END CATCH
  </code></pre>