Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAX Statement 4

Status
Not open for further replies.

PlsHlpKat

IS-IT--Management
Feb 20, 2003
49
US
I have a table with EmpID, Name, Status, Payrate, Effective date, etc. showing employee status changes there is a new record for each change. I need to do two things with the table.
1. A report: I need to do a query to pull the record for each employee that has the latest <Eff date>.
2. A Form: I need to list the current payrate on a form which can also be pulled by the latest <Eff Date>.

My code is not working I am getting Syntax error am I doing something wrong?


SELECT[CLOCK #], [Last Name], [First Name], [Hire Date], Status, [EFF Date], [Review Date], Action, [Rating Code], [Increase Amt], [Inc Perct], [Pay Rate], [Next Review], [Department/Team], [Cost Center], [Job Code/Title], Supervisor, Code
FROM [Employee Performance Reviews] As T

Where T.[EFF Date]IN(Select MAX(EFF Date) From[Employee Performance Reviews] As X Where X.CLOCK # = T.CLOCK #;

Thanks

Kat
 
Hi

This query will pull the latest EFF Date for each employee, so can be used as the recordsource for your report:

SELECT [CLOCK #], [Last Name], [First Name], [Hire Date], Status, Max ([EFF Date]), [Review Date], Action, [Rating Code], [Increase Amt], [Inc Perct], [Pay Rate], [Next Review], [Department/Team], [Cost Center], [Job Code/Title], Supervisor, Code
FROM [Employee Performance Reviews] As T
GROUP BY CLOCK #], [Last Name], [First Name], [Hire Date], Status, [Review Date], Action, [Rating Code], [Increase Amt], [Inc Perct], [Pay Rate], [Next Review], [Department/Team], [Cost Center], [Job Code/Title], Supervisor, Code

This will also pull the pay rate off at the latest value, so can be used for the form in a read only manner, but this won't be able to be edited because of the Group by statement.

John
 
Yes. You don't have a closing ) for the select query in the where clause.
 
I copied your code word for work and I am still getting all records???

Kat
 
You may need to go back to the first construct. You are getting all records in the GROUP BY because one or more of the fields in the grouped fields have different values. Try this
Code:
SELECT [CLOCK #], [Last Name], [First Name], [Hire Date], Status, [EFF Date], [Review Date], Action, [Rating Code], [Increase Amt], [Inc Perct], [Pay Rate], [Next Review], [Department/Team], [Cost Center], [Job Code/Title], Supervisor, Code

FROM [Employee Performance Reviews] As T

Where T.[EFF Date] IN

(Select MAX([EFF Date]) From [Employee Performance Reviews] As X 
 Where X.[CLOCK #] = T.[CLOCK #])
I've added [] around 'EFF Date', 'CLOCK #' and a ) at the end and inserted spaces where needed.
 
Hey Golom,

Thanks for the great code! You just helped me solve a pretty big problem without my having to ask a single question! Have a star!

Brenda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top