title: Performing a bitwise sum
body: <p>As part of a complex aggregate I want to know the <em>bitwise</em> sum of some data, i.e. if I have rows with values 1,1,1,2,2,8 the <em>bitwise</em> sum is 11. In this case the values are all exact powers of two (single bits), so I can hack around it by grouping and summing over the groups (obviously this example is a bit tortured compared to the real query):</p>
  
  <pre><code>select SUM(y.test)
  from (
      select x.test
      from ( -- garbage test data
          select 1 as [test]
          union all select 1
          union all select 1
          union all select 2
          union all select 2
          union all select 8) x
  group by x.test) y
  </code></pre>
  
  <p>but is there a clean way to perform a bitwise sum in [T]SQL?</p>