• Not sure if this is what you are looking for. This is assuming OrderID is the correct order you want.

    SELECT TaskID

    ,TaskDate

    ,OrderID

    ,TrueOrderID = ROW_NUMBER() OVER(ORDER BY TaskDate ASC)

    FROM #tblTasks

    ORDER BY OrderID

    Then you could compare the OrderID to TrueOrderID