Max function not working (1 Viewer)

aliikhlaq2006

Registered User.
Local time
Tomorrow, 02:07
Joined
Aug 10, 2017
Messages
17
I need a result which displays the MAX date but its not working
PARAMETERS [Enter Month And Year (mm/yyyy)] Text ( 255 );
SELECT Advance.EmployeeID, Employees.Name, Advance.PayBack, (SELECT Sum(taken-payback) FROM advance SUB where employeeid=advance.employeeid and [Trdate]<=advance.Trdate) AS Balance, (SELECT Max(Trdate) FROM advance SUB where trdate=advance.Trdate) AS Datesw
FROM Employees INNER JOIN Advance ON Employees.ID = Advance.EmployeeID
GROUP BY Advance.EmployeeID, Employees.Name, Advance.PayBack, Format(Month([Trdate]),"00") & "/" & Year([Trdate]), Advance.Trdate
HAVING (((Format(Month([Trdate]),"00") & "/" & Year([Trdate]))=[Enter Month And Year (mm/yyyy)]))
ORDER BY Advance.EmployeeID, Advance.Trdate;
I also try to run without the subquery "Datesw" and use field but not works for me
 

plog

Banishment Pending
Local time
Today, 17:07
Joined
May 11, 2011
Messages
11,645
Define 'not working'. Error message? Unexpected results? No results? Causing blindness or incontinence? Ripping the local space/time continuum?
 

isladogs

MVP / VIP
Local time
Today, 23:07
Joined
Jan 14, 2017
Messages
18,216
So what happens when you run it with and without the subquery.
Do you get an error or does it give the wrong results?

One suggestion - use date format yyyymm (or yyyymmdd if date field includes day of month) as this will correctly sort latest date value
 

Mark_

Longboard on the internet
Local time
Today, 15:07
Joined
Sep 12, 2017
Messages
2,111
Have you tried it without the SUB where trdate=advance.trdate ?
 

aliikhlaq2006

Registered User.
Local time
Tomorrow, 02:07
Joined
Aug 10, 2017
Messages
17
So what happens when you run it with and without the subquery.
Do you get an error or does it give the wrong results?

One suggestion - use date format yyyymm (or yyyymmdd if date field includes day of month) as this will correctly sort latest date value

There is no error it gives all result not select the MAX date in both cases
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:07
Joined
Feb 28, 2001
Messages
27,172
I am not familiar with the intent of the word SUB appearing in the sub-query preceding the WHERE clause. What is the intent of that item (which IS a keyword in Access and therefore can cause headaches)?
 

Users who are viewing this thread

Top Bottom