title: inner loop sum of multiple columns
body: <pre><code>SELECT total, 
         upto10, 
         emi, 
         repo, 
         arrear, 
         res, 
         [pi], 
         Sum(emi1)        EMI, 
         Sum(repo1)       REPO, 
         Sum(repo_arrear1)REPO_ARR, 
         Sum(res1)        RESO, 
         Sum(pi1)         [PI], 
         Sum(( ( Sum(emi) / 100 ) + ( Sum([repo_arrear1]) / 100 ) ) / 
                 ( ( total * 35 ) / 100 ) / 0.01) 
  FROM   (SELECT Sum(total)                                           total, 
                 Sum(Cast(( ( total * 55 ) / 100 ) AS DECIMAL(8, 2))) upto10, 
                 Sum(emi)                                             EMI, 
                 Sum(repo)                                            repo, 
                 Sum([repo arrear])                                   arrear, 
                 Sum(Cast(( res ) AS DECIMAL(8, 2)))                  res, 
                 Sum([pi])                                            [pi], 
                 Cast(( Sum(emi) / 100 ) AS DECIMAL(2, 2))            EMI1, 
                 Sum(repo)                                            repo1, 
                 Cast(( Sum([repo arrear]) / 100 ) AS DECIMAL(2, 2))  REPO_ARREAR1 
                 , 
                 Cast((Sum(emi)/100) AS DECIMAL(2, 2)) 
                 + Cast((Sum([repo arrear])/100) AS DECIMAL(2, 2))    res1, 
                 Cast(( Sum([pi]) / 100 ) AS DECIMAL(2, 2))           [PI1], 
                 Sum(( ( Sum(emi) / 100 ) + ( Sum([repo arrear]) / 100 ) ) / ( 
                     ( total * 35 ) / 100 ) 
                     / 0.01)                                          AS emi2 
          FROM   [DCRA].[dbo].[dcc] 
          WHERE  curr_date BETWEEN '2014-01-01' AND '2014-02-20' 
                 AND circle = 'C1')AS a 
  GROUP  BY total, 
            emi, 
            upto10, 
            repo, 
            arrear, 
            res, 
            [pi], 
            emi2 
  </code></pre>
  
  <p>error message:Cannot perform an aggregate function on an expression containing an aggregate or a subquery.</p>