title: Cannot perform an aggregate function on an expression containing an aggregate or a subquery but need filtered results
body: <p>I've got the error message for the following codes</p>
  
  <p>as in a nested query</p>
  
  <pre><code>FROM(
      SELECT  SUM(CASE (select TotalBasePayAnnualizedAmt from WDHRISedw.edaHR.WorkerPosition where WDHRISedw.edaHR.WorkerPosition.EmployeeID = Employee_ID) 
                  WHEN NULL THEN 0 
                  WHEN 0 THEN 0 
                  ELSE GrossPay / (select TotalBasePayAnnualizedAmt from WDHRISedw.edaHR.WorkerPosition where WDHRISedw.edaHR.WorkerPosition.EmployeeID = Employee_ID) * 200 
              END
              ) AS [Paid FTE],
          Employee_ID, 
          Position_ID, EarnedPeriodEndDate
          FROM
          WDHRISods.WD.ActualDistributions
  </code></pre>
  
  <p>how to modify to avoid the error?</p>