title: How should a T-SQL script detect if it's running in Azure SQL Database or on-premise?
body: <p>Suppose I have a piece of T-SQL that gets variously run both on Azure SQL Database and on-premise SQL Server. How can I programmatically detect, <em>within the script itself</em>, which of these is the prevailing context?</p>
  
  <p>I note that</p>
  
  <pre><code>SELECT @@VERSION
  </code></pre>
  
  <p>on Azure SQL Database yields a string that starts</p>
  
  <pre><code>Microsoft SQL Azure 
  </code></pre>
  
  <p>but parsing the output of <code>@@VERSION</code> doesn't make for a nice feeling, and of course the specifics could change at any time.</p>
  
  <p>Is there a more-obviously-correct way of doing this?</p>