Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Check a number against several ranges

Posted on 2006-06-05
2
Medium Priority
?
215 Views
Last Modified: 2010-04-16
Hello,

I have a database table which has three columns: From | To | Value

What I want is to check a number that I get to which range it belongs so I can return the Value of that row.

For example for table like:

0 | 100 | 30
101 | 200 | 50

if I am given the number 148 I want to return 50.

What's the easiest way of doing that?

Thank you!!
0
Comment
Question by:infodigger
  • 2
2 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 total points
ID: 16836817
Assuming the from and to don't overlap for any record:

select value from table
where from <= @argValue and to >= @argValue
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16836822
or

select value from table
where @argValue between from and to
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

810 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