Solved

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

Posted on 2008-06-18
3
574 Views
Last Modified: 2013-12-07
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
Comment
Question by:crayola3
  • 2
3 Comments
 
LVL 10

Expert Comment

by:MoreHeroic
ID: 21816472
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
 
LVL 10

Accepted Solution

by:
MoreHeroic earned 70 total points
ID: 21816480
Ah, I see inclusive, sorry:

SELECT *
FROM tblRange
WHERE n >= intStart AND n <= intEnd
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 55 total points
ID: 21816743
   "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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now