SQL problem with checking next and previous rows
How about a rewrite of it?

;with eMK_Mileage
AS (SELECT 15755 AS ID, '8E79F' AS FK_CarID, 69646 AS KM , '20140716' AS KM_Date UNION ALL
SELECT 15756,'8E79F' , 70393 , '20140726' UNION ALL
SELECT 15757,'8E79F' , 58258 , '20140822' UNION ALL
SELECT 15758,'8E79F' , 72055 , '20140822')
,FullList 
AS (
 SELECT  * FROM eMK_Mileage as Mileage
)
-- FINAL SELECT
SELECT
*
,CASE WHEN FL.KM &lt; ISNULL(P.KM_PREV,FL.KM) THEN 0 ELSE 1 END AS validKMstand
,CASE WHEN FL.KM &gt; ISNULL(N.KM_NEXT,FL.KM) THEN 0 ELSE 1 END AS validKMstand2   
FROM 
FullList AS FL
OUTER APPLY 
--PREVIOUS ROW
(SELECT TOP 1 
        KM AS KM_PREV
    FROM FullList AS PREV
    WHERE
        FL.FK_CarID = PREV.FK_CarID
        AND FL.KM_Date&gt;=PREV.KM_Date
        AND FL.ID&gt;PREV.ID
    ORDER BY 
        KM_Date DESC, ID DESC
)AS P
--NEXT ROW
OUTER APPLY 
(SELECT TOP 1 
        KM AS KM_NEXT
    FROM FullList AS NXT
    WHERE
        NXT.FK_CarID = FL.FK_CarID
        AND NXT.KM_Date&gt;=FL.KM_Date
        AND NXT.ID &gt; FL.ID
    ORDER BY 
        KM_Date ASC, ID ASC
)AS N
ORDER BY ID,KM_Date


the output, for my sample is this:

ID  FK_CarID    KM  KM_Date KM_PREV KM_NEXT validKMstand    validKMstand2
15755   8E79F   69646   20140716    NULL    70393   1   1
15756   8E79F   70393   20140726    69646   58258   1   0
15757   8E79F   58258   20140822    70393   72055   0   1
15758   8E79F   72055   20140822    58258   NULL    1   1