Here is my SQL statement:
SELECT A.last, A.first, A.mpotc, C.clas_Title, A.mdoe, A.sdoe, A.dob, B.h_Salary ;
FROM EMP_MAST A RIGHT JOIN EMP_HIST B ON A.SSN = B.SSN AND B.Effect_dat IN ;
(SELECT MAX(Effect_dat) FROM EMP_HIST WHERE EMP_HIST.SSN = EMP_MAST.SSN) ;
JOIN CLASSCOD C ON C.Class_code = B.H_classcd ;
WHERE A.STATUS = 'A'
I have to find the one EMP_HIST record that has the latest effect_dat not greater that today's date. Generally the very last physical record in the table with a matching ssn.
I still need to code to make sure that I don't get a record with a future effect_dat, but I thought I would come back to that after I succeeded getting the very last emp_hist record in the query. And there could be 2 records entered on the same day, with the same effect_dat, so I always want the last one entered.
This is a legacy system with a poor design and its not easy getting the information I need.
Thanks for any help!
SELECT A.last, A.first, A.mpotc, C.clas_Title, A.mdoe, A.sdoe, A.dob, B.h_Salary ;
FROM EMP_MAST A RIGHT JOIN EMP_HIST B ON A.SSN = B.SSN AND B.Effect_dat IN ;
(SELECT MAX(Effect_dat) FROM EMP_HIST WHERE EMP_HIST.SSN = EMP_MAST.SSN) ;
JOIN CLASSCOD C ON C.Class_code = B.H_classcd ;
WHERE A.STATUS = 'A'
I have to find the one EMP_HIST record that has the latest effect_dat not greater that today's date. Generally the very last physical record in the table with a matching ssn.
I still need to code to make sure that I don't get a record with a future effect_dat, but I thought I would come back to that after I succeeded getting the very last emp_hist record in the query. And there could be 2 records entered on the same day, with the same effect_dat, so I always want the last one entered.
This is a legacy system with a poor design and its not easy getting the information I need.
Thanks for any help!