title: CASE Statement SQL: Priority in cases?
body: <p>I have a general question for when you are using a CASE statement in SQL (Server 2008), and more than one of your WHEN conditions are true but the resulting flag is to be different.</p>
  
  <p>This is hypothetical example but may be transferable when applying checks across multiple columns to classify data in rows. The output of the code below is dependant on how the cases are ordered, as both are true.</p>
  
  <pre><code>DECLARE @TESTSTRING varchar(5)
  SET @TESTSTRING = 'hello'
  
  SELECT CASE 
  WHEN @TESTSTRING = 'hello' THEN '0'
  WHEN @TESTSTRING &lt;&gt; 'hi' THEN '1'
  ELSE 'N/A' 
  END AS [Output]
  </code></pre>
  
  <p>In general, would it be considered bad practice to create flags in this way? Would a WHERE, OR statement be better?</p>