1
I have a table with the model below (consistent data):
CODIGO | INICIO | FIM
1 | 2018 | NULL
1 | 2017 | 2017
1 | 2014 | 2016
I need to find the records where the INICIO
has the same value as FIM
previous, as below, where the data of lines 1 and 2 are inconsistent:
CODIGO | INICIO | FIM
1 | 2018 | NULL
1 | 2017 | 2018
1 | 2014 | 2016
I tried with the query below but do not know what is wrong...
SELECT T.CODIGO, T.INICIO, T.FIM, X.*
FROM TABELA T
CROSS APPLY (
SELECT T1.CODIGO, T1.INICIO, T1.FIM
FROM TABELA T1
WHERE T1.CODIGO = T.CODIGO
AND T1.INICIO = T.FIM
) X
Thank you!