title: How to improve a case statement that uses two columns
body: <p>I have a table called Purchase which has a State column, where 1 is authorized, 2 is completed (there are some other values too).</p>
  
  <p>I also have a Retailer table, which has a column RetailerProcessType, where 1 is one-step and 2 is two-step.</p>
  
  <p>I have the query below:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CASE purc.State
      WHEN 1 THEN '"AUTHORISED"'
      WHEN 2 THEN '"AUTHORISED"'
      WHEN 4 THEN '"AUTHORISED"'
      ELSE '"DECLINED"'
   END                                                                     
   AS Autorised_Decline_Status,
  </code></pre>
  
  <p>But what I need to do is as follows:</p>
  
  <pre class="lang-sql prettyprint-override"><code>WHEN STATE = 2 AND RetailerProcessType = 1 THEN '"AUTHORISED"'
  WHEN STATE = 1 AND RetailerProcessType = 2 THEN '"PENDING"'
  WHEN STATE = 2 AND RetailerProcessType = 2 THEN '"AUTHORISED"'
  ELSE '"DECLINED"'
  </code></pre>
  
  <p>The only way I can think of doing this is having a massive <code>IF</code> statement around the query, one for a one-step retailer and another for a two-step, as my understanding is a <code>WHEN</code> clause cannot have an <code>AND</code> in it.</p>
  
  <p>However, this just seems long winded; anybody have any neater ideas?</p>