title: Error with aggregate function
body: <p>when i execute the below query i get the error "Cannot perform an aggregate function on an expression containing an aggregate or a subquery." How can i write the same query without getting the error.</p>
  
  <pre><code>SELECT CCMID[Client],CCMName[Company],
      (SELECT SUM( (Select SUM( PAm) from PaySalReg(NOLOCK) 
      Join PayEleMas (NOLOCK) ON  PSPCo =PEPCo
      where PSRAMId=AMId and PEMDedTy ='SSC' 
      and PProYe=(SELECT DOYe FROM DefOMonth)
      and PProMo=(SELECT DOMo-1 FROM DefOMonth))
      -
      (Select SUM(PAm) from PaySalReg(NOLOCK) 
      Join PayEleMas (NOLOCK) ON  PSPCo =PEPCo
      where PSRAMId=AMId and PEMDedTy ='PRTY'
      and PProYe=(SELECT DOYe FROM DefOMonth)
      and PProMo=(SELECT DOMo-1 FROM DefOMonth)))
      from AssMas(NOLOCK) WHERE ACID = CCMID ) AS [Net Pay],
      COUNT(PAMId)[No. of Associates] 
      FROM PaySalReg
      JOIN AssMas ON AMId =PSRAMId
      JOIN CorpClMas ON ACID = CCMID
      WHERE PProMon='10'
      AND PProYe='2014'
      AND PAPPSTA IS NULL
      GROUP BY CCM_Name,CCM_ID
  </code></pre>