SQL get row based on condition
This is just a guess on my behalf, it is not clear to me how you define highest row and next operation:

select ProdId, max(OprNum)
from (
    select ProdId, max(OprNum) as OprNum 
    from ProdRoute pr1 
    where not exists ( 
        select 1 
        from ProdRoute pr2 
        where pr1.ProdId = pr2.ProdId
          and pr1.OprNum = pr2.OprNum 
          and SetupTime + ProcessTime &gt; 0
    ) 
    group by ProdId 
    union all 
    select ProdId, min(OprNum) as OprNum 
    from ProdRoute pr1 
    where exists ( 
        select 1 
        from ProdRoute pr2 
        where pr1.ProdId = pr2.ProdId 
          and pr1.OprNum = pr2.OprNum 
          and SetupTime + ProcessTime &gt; 0
    ) 
    and not exists (
        select 1 
        from ProdRouteTran prt 
        where pr1.ProdId = prt.ProdId 
          and pr1.OprNum &lt;= prt.MaxOpCompleted
    ) 
    group by ProdId
) as t
group by ProdId;