I have the following query:
SELECT
CODIGO,
DTINICIO AS INICIO,
DTFINAL AS FINAL
FROM PFHSTAFT
WHERE
EMPRESA =1
GROUP BY
CODIGO,
DTFINAL,
DTINICIO
It returns as follows:
0031 2000-11-06 00:00:00.000 2001-12-31 00:00:00.000
0031 2002-02-26 00:00:00.000 2002-06-30 00:00:00.000
0031 2002-09-26 00:00:00.000 2008-03-17 00:00:00.000 <<<<<
0051 2003-04-23 00:00:00.000 2016-09-05 00:00:00.000
0051 2016-10-06 00:00:00.000 2016-10-15 00:00:00.000
0051 2016-10-18 00:00:00.000 2016-10-22 00:00:00.000 <<<<<
0051 2016-11-01 00:00:00.000 NULL
But I need to list only the last end date of each employee, which is represented by the code:
0031 2002-09-26 00:00:00.000 2008-03-17 00:00:00.000
0051 2016-10-18 00:00:00.000 2016-10-22 00:00:00.000
I tried to use max but it did not answer; does anyone know what it can be?
BANK: SQL SERVER 2008