[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 584
  • Last Modified:

SQL - determine if a given number does not lie within any range of numbers within a set of ranges

Is there an easy way to determine if a given integer is not within a set of ranges of integers?  I have a table - tblRange with columns intStart and intEnd.  Each record in tblRange consists of records similar to this: intStart = 5, intEnd = 10; intStart = 1, intEnd = 6; intStart = 11, intEnd = 20, etc.  For each record, intStart is always >= intEnd and intStart >= 0.  Given n, how can determine if n does not lie within (inclusive) any of tblRange's records ranges?
0
crayola3
Asked:
crayola3
  • 2
2 Solutions
 
MoreHeroicCommented:
SELECT *
FROM tblRange
WHERE n > intStart AND n < intEnd

If records are returned n is in that record's range.  if no records are returned it lies outside all the ranges.
0
 
MoreHeroicCommented:
Ah, I see inclusive, sorry:

SELECT *
FROM tblRange
WHERE n >= intStart AND n <= intEnd
0
 
sdstuberCommented:
   "intStart is always >= intEnd and intStart >= 0"

is that an error?

from your examples  intStart < intEnd.  not >=

can intStart be greater than intEnd?  can they be equal?
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now