Nest SUM() Function Inside Case Statement?
You need to remove the outer case statement. It should be:

Select sum( case when ..... then .... end) from foo


You have 

Select case when sum(case when.... then .... end) end from foo


The when clause expects something that will resolve to either true or false. That's what your error message is trying to tell you.



I'm still not 100% sure what your end goal is but you either need to remove the wrapping case statement like I said above or pull the case condition out of the sum.

Select
   Case 
       When &lt;condition &gt; then sum(&lt;column&gt;)
        When &lt;condition &gt; then sum(&lt;column &gt;)
         Else sum(&lt;column &gt;)
         End
From foo