Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a Vlookup "true" to match nearest value, but in Access

Status
Not open for further replies.

verizonrep

Programmer
Oct 29, 2002
48
US
I am working on a project where I need to do a Vlookup-type function (true, not false-type) in Access rather than Excel. I have a value in one table that needs to be checked against a list and when it passes one level, it moves to the next one.

Something like this.

Lookup_Table
Level Value
10 1
15 2
20 3


If I put in a different table a value it 5, I need it to be able to reference the table above and return a 1. If it moves to 10.1, it will return a value of 2. Once it passes the 15 level, it moves to 3. This is basically like doing a vlookup in Excel with a "true" range condition.

Can this can be done in a query or a table?

Anyone got an idea???

 
So are you saying everything in the range of 0-14 should return a 1, everything from 15-19 returns a 2 and everything that is 20 or greater will be a 3?


Thanks,

Steve





 
More like:

0-10 returns a 0 (probably need to show that in the table)
10.000000001 - 15 returns a 1
15.000000001 - 20 returns a 2
anything higher than 20 returns a 3

Basically, the moment it passes a level, it moves on to the next one (hence the .000000001 after some of the numbers).

 
It can be done in a query.

Suppose you want the result for an input level of 16.

Then this should work:

SELECT T1.Value
FROM Lookup_Table T1
WHERE T1.Level =
(
SELECT MAX(Level)
FROM Lookup_Table T2
WHERE T2.Level <= 16
)

What we are doing in the inner SELECT is finding the highest Level not exceeding 16 and feeding that result to the outer SELECT.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top