I'm not sure what you want for output. It's also, very helpful if you put sample data in a consumable format (i.e. - CREATE Table and insert statements). Here is something I put together than might help:DECLARE @Operation TABLE (workorde_base INT, sequence_no INT, resource_id VARCHAR(50))INSERT @Operation VALUES(14071, 10, 'SHEAR'),(14071, 10, 'IRONWORKER'),(14071, 10, 'BRAKE'),(14071, 10, 'CLEANING'),(14071, 10, 'PAINT');WITH Cte AS( SELECT *, ROW_NUMBER() OVER (PARTITION BY workorde_base ORDER BY sequence_no) AS RowNum FROM @Operation)SELECT *FROM Cte AS BaseLEFT OUTER JOIN Cte AS Prev ON Base.workorde_base = Prev.workorde_base AND Base.RowNum = Prev.RowNum + 1LEFT OUTER JOIN Cte AS Next ON Base.workorde_base = Next.workorde_base AND Base.RowNum = Next.RowNum - 1WHERE Base.resource_id = 'BRAKE'