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
576 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MULTIPLE DATE QUERY 15 81
exp/imp 25 76
Server running out of memory - Something is consuming all the available memory 17 64
SQL Workhours Count beetween Workhours 3 20
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Creating and Managing Databases with phpMyAdmin in cPanel.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

825 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