I have a request that should return the lowest balance for this month for each identifier. The problem I get is to return multiple balances instead of the minimum balance on the Balance. I keep getting these results:
ID Name Month Year TodayMonth TodayYear BalMin
1 A 4 12 4 2012 10,000.00
1 A 4 12 4 2012 20,000.00
When I need to return the lowest balance:
ID Name Month Year TodayMonth TodayYear BalMin
1 A 4 12 4 2012 10,000.00
Here is what I still have:
SELECT DISTINCT
TOP (100) PERCENT History.ID, info.Name, DATEPART(mm, History.ReportDate) AS Month, DATEPART(yy,History.ReportDate) AS Year, DATEPART(mm, { fn CURDATE() }) AS TodayMonth, DATEPART(yy, { fn CURDATE() }) AS TodayYear, MIN(History.Balance) AS BalMin
FROM History LEFT OUTER JOIN Info ON History.ID = Info.ID
WHERE (DATEPART(yy, History.ReportDate) = DATEPART(yy, { fn CURDATE() })) AND (DATEPART(mm, History.ReportDate) = DATEPART(mm,
{ fn CURDATE() })) AND (History.Balance > 0)
GROUP BY History.ID, History.ReportDate, Info.Name, History.Balance
ORDER BY History.ID
source
share