Solved Lookup values in a range

AnilBagga

Member
Local time
Tomorrow, 02:21
Joined
Apr 9, 2020
Messages
223
I have 2 sample tables as in the enclosed DB file

1. tblItemMaster which has PartNo and a DFL value for each item
2. tblValueAdd which have a Value add for a min and max value of DFL

What is the most efficient way to build a query where I can get the ValueAdd for each item in the tblItemMaster?

I have done this in multiple ways but not sure what is the best and most efficient way.

Would appreciate some advise
 

Attachments

How about:

SELECT tblItemMaster.ItemCode, tblItemMaster.DFL, tblValueAdd.ValueAdd
FROM tblItemMaster INNER JOIN tblValueAdd ON (tblItemMaster.DFL <= tblValueAdd.DFLMax) AND (tblItemMaster.DFL >= tblValueAdd.DFLMin);

Note it can't be represented in design view, only SQL view.
 
How about:

SELECT tblItemMaster.ItemCode, tblItemMaster.DFL, tblValueAdd.ValueAdd
FROM tblItemMaster INNER JOIN tblValueAdd ON (tblItemMaster.DFL <= tblValueAdd.DFLMax) AND (tblItemMaster.DFL >= tblValueAdd.DFLMin);

Note it can't be represented in design view, only SQL view.
Thanks. 🙏
 
Happy to help!
Hi pbaldy,

I tried to be adventurous and tried to do a 3 way left join between 2 tables. I got over the syntax errors with some searching but the values to be fetched are not showing - "Rate" and "Waste" in qryTapeValueAdd. Where am I going wrong?
 

Attachments

It cannot be done in one query without Dlookup? Dlookups I hear slow down queries
 
You have a join between Category and RM, but they don't contain any matching values so you'll never pull a value from the ValueAdd table:

1618591471303.png
 
The color fields don't appear to match up either.
 
You have a join between Category and RM, but they don't contain any matching values so you'll never pull a value from the ValueAdd table:

View attachment 90879
With the IIF condition the values match. I made a dummy data of the TapeCodeMastertbl with results of the IIF condition as values and the Query works. This means the results of the IIF condition are not considered as values of the table in the JOIN statements.

So I guess a 2 stage query as suggested by ArnelGP with Dlookup's in the second query is the only solution.
 
you're welcome Anil.
 

Users who are viewing this thread

Back
Top Bottom