I have a query that works, I wanted to add another sum from another table, but when I do, the all the SUM values are wrong
this works
SELECT Clients.ClientID, Clients.WholeName,
SUM(CASE WHEN Payments.Creditorid = 0 THEN Payments.Amount ELSE 0.00 END) AS 'Admin Fees',
SUM(CASE WHEN (Payments.Creditorid = 3) THEN Payments.amount ELSE 0.00 END) AS 'Retainer Fees',
SUM(CASE WHEN (Payments.Creditorid = 4) THEN Payments.amount ELSE 0.00 END) AS 'Finance Fees',
SUM(CASE WHEN (Payments.Creditorid = 2) THEN Payments.amount ELSE 0.00 END) AS 'NSF Fees',
SUM(CASE WHEN Payments.bankaccountid = 0 THEN Payments.amount ELSE 0.00 END) AS Settlements
FROM Clients LEFT OUTER JOIN
Payments ON Clients.ClientID = Payments.ClientID
WHERE (Clients.ClientID = 1126)
GROUP BY Clients.ClientID, Clients.WholeName
ORDER BY Clients.ClientID
this does not
SELECT Clients.ClientID, Clients.WholeName,
SUM(CASE WHEN Payments.Creditorid = 0 THEN Payments.Amount ELSE 0.00 END) AS 'Admin Fees',
SUM(CASE WHEN (Payments.Creditorid = 3) THEN Payments.amount ELSE 0.00 END) AS 'Retainer Fees',
SUM(CASE WHEN (Payments.Creditorid = 4) THEN Payments.amount ELSE 0.00 END) AS 'Finance Fees',
SUM(CASE WHEN (Payments.Creditorid = 2) THEN Payments.amount ELSE 0.00 END) AS 'NSF Fees',
SUM(CASE WHEN Payments.bankaccountid = 0 THEN Payments.amount ELSE 0.00 END) AS Settlements,
SUM(Receipts.ReceiptAmount) AS 'Total Receipts'
FROM Clients LEFT OUTER JOIN
Receipts ON Clients.ClientID = Receipts.ClientID LEFT OUTER JOIN
Payments ON Clients.ClientID = Payments.ClientID
WHERE (Clients.ClientID = 1126)
GROUP BY Clients.ClientID, Clients.WholeName
ORDER BY Clients.ClientID