How to check if range between two numbers is available in table of ranges
select count(*)
from ( select RangeTo, LEAD(RangeFrom, 1, 0) OVER (ORDER BY RangeTo) 
                       AS LeadRangFrom 
       from table 
     ) ss 
where @RangeFrom &gt; RangeTo 
  and ( @RangeTo &lt; LeadRangFrom or LeadRangFrom is null) 


If count(*) is one then you can insert
Is that the question you are asking?