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
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 74

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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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