Select *
  from (Select SO.Contract,
               SO.Part_No,
               Inventory_Part_API.Get_Description(SO.Contract, SO.Part_No) Description,
               SOO.RESOURCE_ID,
               SO.Order_No,
               SO.Release_No,
               SO.Sequence_No,
               lag(HU.HANDLING_UNIT_ID, 1, 0) over(Partition By SO.Order_No, SO.Release_No, SO.Sequence_No, SO.Part_No Order By SO.Order_No, SO.Release_No, SO.Sequence_No, SO.Part_No, HU.HANDLING_UNIT_ID) Previous_HU,
               HU.HANDLING_UNIT_ID Next_HU
               
              ,
               HU.HANDLING_UNIT_ID - CASE
                 WHEN lag(HU.HANDLING_UNIT_ID, 1, 0)
                  over(Partition By SO.Order_No,
                           SO.Release_No,
                           SO.Sequence_No,
                           SO.Part_No Order By SO.Order_No,
                           SO.Release_No,
                           SO.Sequence_No,
                           SO.Part_No,
                           HU.HANDLING_UNIT_ID) = 0 then
                  HU.HANDLING_UNIT_ID
                 else
                  lag(HU.HANDLING_UNIT_ID, 1, 0)
                  over(Partition By SO.Order_No,
                       SO.Release_No,
                       SO.Sequence_No,
                       SO.Part_No Order By SO.Order_No,
                       SO.Release_No,
                       SO.Sequence_No,
                       SO.Part_No,
                       HU.HANDLING_UNIT_ID)
               end Seq_Gap
        
          From Shop_Ord SO
         inner join HANDLING_UNIT_EXTENDED HU
            on SO.Order_No = HU.SOURCE_REF1
           and SO.Release_No = HU.SOURCE_REF2
           and SO.Sequence_No = HU.SOURCE_REF3
         inner join SHOP_ORDER_OPERATION SOO
            on SOO.Order_No = SO.Order_No
           and SOO.Sequence_No = SO.Sequence_No
           and SOO.Release_No = SO.Release_No
        
         Where SO.Contract LIKE '%&Contract%'
           and SO.State in ('Started')
           and SOO.Operation_No = '10'
        
         Order By SOO.RESOURCE_ID,
                  SO.Order_No,
                  SO.Release_No,
                  SO.Sequence_No,
                  HU.HANDLING_UNIT_ID) SQ1

 Where Seq_Gap > 1
 Order By Contract,
          RESOURCE_ID,
          Order_No,
          Release_No,
          Sequence_No,
          Previous_HU