Need some help with a query. I'm trying to show the first date for each client where beginning balance = 0, ending balance > 0. The query below works for the most part because almost all clients only have 1 record where balance = 0 and ending balance > 0. However, I noticed that one client has 2 records where this occurred and so I only want to show the earliest date in this situation.
Here's what I have so far and I'm sure there is a much more efficient way of doing this but I have very limited SQL knowledge:
Code:
SELECT tblAccountHistory.ClientID, tblAccountHistory.TransDate, Sum(tblAccountHistory.BegBal) AS SumOfBegBal, Sum(tblAccountHistory.NetContributions) AS SumOfNetContributions, Sum(tblAccountHistory.NetInvestmentChange) AS SumOfNetInvestmentChange, Sum(tblAccountHistory.EndingBal) AS SumOfEndingBal
FROM tblAccountHistory INNER JOIN tblClients ON tblAccountHistory.ClientID = tblClients.client
GROUP BY tblAccountHistory.ClientID, tblAccountHistory.TransDate, tblClients.cycle
HAVING (((Sum(tblAccountHistory.BegBal))=0) AND ((Sum(tblAccountHistory.EndingBal))>0) AND ((tblClients.cycle)=1));
Thanks in advance