title: Best way to do nested case statement logic in SQL Server
body: <p>I'm writing an SQL Query, where a few of the columns returned need to be calculated depending on quite a lot of conditions.</p>
  
  <p>I'm currently using nested case statements, but its getting messy. Is there a better (more organised and/or readable) way?</p>
  
  <p>(I am using Microsoft SQL Server, 2005)</p>
  
  <hr>
  
  <p>A simplified example:</p>
  
  <pre><code>SELECT
      col1,
      col2,
      col3,
      CASE
          WHEN condition 
          THEN
              CASE
                  WHEN condition1 
                  THEN
                      CASE 
                          WHEN condition2
                          THEN calculation1
                          ELSE calculation2
                      END
                  ELSE
                      CASE 
                          WHEN condition2
                          THEN calculation3
                          ELSE calculation4
                      END
              END
          ELSE 
              CASE 
                  WHEN condition1 
                  THEN 
                      CASE
                          WHEN condition2 
                          THEN calculation5
                          ELSE calculation6
                      END
                  ELSE
                      CASE
                          WHEN condition2 
                          THEN calculation7
                          ELSE calculation8
                      END
              END            
      END AS 'calculatedcol1',
      col4,
      col5 -- etc
  FROM table
  </code></pre>