Sorry.
I couldn't make my point clear.
Derived table is acceptable.
But within that derived table is it possible to find problematic rows
without using self joins like.
........
from cte CurRow
left join cte NextRow
on CurRow.Emp_code = NextRow.Emp_Code
and CurRow.RowNum = NextRow.RowNum + 1
left join cte PrevRow
on CurRow.Emp_code = PrevRow.Emp_Code
and CurRow.RowNum + 1 = PrevRow.RowNum
In my mind is lead/lag, bounded preceding etc (i am very weak on these terms)