title: Azure SQL - How to skip USE statement in Azure SQL while having it work in SQL Server
body: <p>I am trying to update an old script in a production installer so that it can work with both Azure SQL and SQL.
  The problem is that our script is calling USE to switch the database.  On prem we are creating the database, in Azure it will already be created for us... so we are detecting its existence and moving on.  However that is where we are then calling USE to switch, for on prem.</p>
  <p>I was hoping I could skip it like this in Azure</p>
  <pre><code>IF NOT SERVERPROPERTY('edition') = 'SQL Azure'
      USE MYDB
  </code></pre>
  <p>I am still getting the &quot;USE statement is not supported to switch between databases.&quot;
  The hack is to put this into a string and run it with: EXEC sp_executesql</p>
  <p>This works for most things, but I don't think it works with the USE statement.
  Is there any way I can let the Azure SQL parser skip this section, as it will never be executed?</p>
  <p>I am open to SQL based workarounds... but I am trying to avoid rearchitecting the installer.</p>