FireGeek21
Technical User
I need the max 2 check dates for each employee. I was using a temp table for the most recent check date but now I need the check just before it but keep getting ALL checks before the max check. Here is my code:
Attached is a pic of what I am getting. I need something like the following:
Thanks!
FireGeek
(currently using Crystal Reports XI with Lawson 9.01)
Code:
SELECT PAY.COMPANY as tCO, PAY.EMPLOYEE as tEE, MAX(PAY.CHECK_DATE) as tCHKDT
INTO #t
FROM db.PAYTABLE PAY
GROUP BY PAY.COMPANY, PAY.EMPLOYEE
ORDER BY PAY.EMPLOYEE
SELECT db.PAYTABLE.EMPLOYEE, Max(db.PAYTABLE.CHECK_DATE) AS PREVIOUS_CHECK, #t.tCHKDT AS MAX_CHECK
FROM db.PAYTABLE, #t
WHERE db.PAYTABLE.EMPLOYEE = #t.tEE
and db.PAYTABLE.CHECK_DATE <
(SELECT MAX(#t.tCHKDT)
FROM #t
WHERE #t.tCO = db.PAYTABLE.COMPANY
and #t.tEE = db.PAYTABLE.EMPLOYEE)
GROUP BY db.PAYTABLE.EMPLOYEE, db.PAYTABLE.CHECK_DATE, #t.tCHKDT
ORDER BY db.PAYTABLE.EMPLOYEE, prod.dbo.PAYMASTR.CHECK_DATE
drop table #t
Attached is a pic of what I am getting. I need something like the following:
Code:
EMPLOYEE PREVIOUS_CHECK MAX_CHECK
91 2011-05-13 00:00:00:000 2011-11-10 00:00:00:000
93 2016-06-03 00:00:00:000 2016-08-12 00:00:00:000
101 2016-07-01 00:00:00:000 2016-08-12 00:00:00:000
Thanks!
FireGeek
(currently using Crystal Reports XI with Lawson 9.01)