This is my query:
SELECT
Sum(IsNull(CircuitCourtFeeCap, 0) + IsNull(CircuitCourtCourtTime, 0) + IsNull(CircuitCourtWaiverFee, 0) + IsNull(CircuitCourtExpenseFee, 0)) AS TotalApproved,
Sum(IsNull(e.FeeAmountCap, 0)) AS TotalFeeCap,
Sum(IsNull((
SELECT Claimed
FROM [dbo].[CourtTimes] ct
WHERE ct.DocumentNameID = dn.DocumentNameID
), 0)) AS TotalCourtTime
FROM DocumentNames dn
LEFT JOIN Expenses e ON dn.DocumentNameID = e.DocumentNameID
It is super simple. All Sum except this piece of line is not working:
Sum(IsNull((Select Claimed From [dbo].[CourtTimes] ct Where ct.DocumentNameID = dn.DocumentNameID), 0)) As TotalCourtTime
I get this error: Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
Any ideas how to solve this issue?