title: Is replacing conditional logic with CASE statements efficient in Transact-SQL?
body: <p>I have a stored procedure that does something like:</p>
  
  <pre><code>IF @Param = '1'
      SELECT HT.HeaderKey, HT.Description,
             (SELECT SUM(E1) -- E1 is actually a complex expression
              FROM   DetailTable DT INNER JOIN ...
                                    INNER JOIN ...
                                    INNER JOIN ...
              WHERE  DT.HeaderKey = HT.HeaderKey)
      FROM   HeaderTable HT
  ELSE IF @Param = '2'
      SELECT HT.HeaderKey, HT.Description,
             (SELECT SUM(E2) -- E2 is yet another complex expression
              FROM   DetailTable DT INNER JOIN ... -- Here, DetailTable is not
                                    INNER JOIN ... -- joined to the same tables
                                    INNER JOIN ... -- as in the first case
              WHERE  DT.HeaderKey = HT.HeaderKey)
      FROM   HeaderTable HT
  -- Etc. There are five cases.
  </code></pre>
  
  <p>I <em>would like</em> to reduce the query to the following:</p>
  
  <pre><code>SELECT HT.HeaderKey, HT.Description,
         CASE @Param
           WHEN '1'
             (SELECT SUM(E1)
              FROM   DetailTable DT INNER JOIN ...
                                    INNER JOIN ...
                                    INNER JOIN ...
              WHERE  DT.HeaderKey = HT.HeaderKey)
           WHEN '2'
             (SELECT SUM(E2)
              FROM   DetailTable DT INNER JOIN ...
                                    INNER JOIN ...
                                    INNER JOIN ...
              WHERE  DT.HeaderKey = HT.HeaderKey)
           -- Etc.
           ELSE 0
         END
  FROM   HeaderTable HT
  </code></pre>
  
  <p>However, if SQL Server evaluates <em>all</em> the cases, regardless of which one will be actually returned, the modified query would be grossly inefficient.</p>
  
  <p>Thus, I'd like to know, does SQL Server evaluate <em>all</em> the cases in a <code>CASE</code> statement, or only the first one that satisfies the <code>CASE</code>'s condition?</p>