title: Multiple columns within a single CASE statement
body: <p>I'm sure this has be covered many times so please pardon my repeat. I have a query that works but currently has 6 CASE statements within one select. Someone mentioned that it would be best optimized by putting all my WHEN conditions within a single CASE. However, I'm unable to achieve this</p>
  
  <pre><code>select right(RTRIM(region),5) as cell_id, 
       sum(CASE WHEN LEFT(cparty,3) in ('999','998','997') THEN chargeduration/60 else 0 END) AS OnNet_Minutes,
       sum(CASE WHEN LEFT(cparty,3) in ('996','995') THEN chargeduration/60 else 0 END) AS OffNet_C_Minutes,
       sum(CASE WHEN LEFT(cparty,3) in ('994','993','992') THEN chargeduration/60 else 0 END) AS OffNet_A_Minutes,
       sum(CASE WHEN LEFT(cparty,3) in ('991','990') THEN chargeduration/60 else 0 END) AS OffNet_S_Minutes,
       sum(CASE WHEN LEFT(cparty,2) = '00' THEN chargeduration/60 else 0 END) AS OffNet_T_Minutes,
       sum(CASE WHEN len(cparty) &lt; 6 and LEFT(cparty,1) &lt;&gt; 0 THEN chargeduration/60 else 0 END) AS SC_Minutes            
    from August.dbo.cdr20130818 
    where CHARGEDURATION &gt; 0 and ISNULL(region,'''')&lt;&gt;'''' and LEN(region) &gt; 5
  group by right(RTRIM(region),5)
  order by right(RTRIM(region),5) asc
  </code></pre>