Dlookup In Query (1 Viewer)

spet

Registered User.
Local time
Today, 06:13
Joined
Oct 5, 2018
Messages
38
I'm trying to execute this query to return a value from another table(GradeAQualityAdjustment).

SELECT CheckStubInfo.PatronNo, CheckStubInfo.[BF%], CheckStubInfo.SCC, CheckStubInfo.Bacteria, CheckStubInfo.[Protein%], Round(IIf((350-([CheckStubInfo].[SCC]/1000))>0,(350-([CheckStubInfo].[SCC]/1000))*[Pricing Info].[SCC Premium Price]),2) AS SCCAvg, DLookUp("QualityAdjustment","GradeAQualityAdjustment",[CheckStubInfo].[SCC] Between DLookUp("BegQuality","GradeAQualityAdjustment") And DLookUp("EndQuality","GradeAQualityAdjustment")) AS QualityAdj
FROM [Pricing Info] INNER JOIN CheckStubInfo ON [Pricing Info].Date = CheckStubInfo.Date
WHERE ((([Pricing Info].Date)=[CheckStubInfo].[Date]) AND ((CheckStubInfo.Grade)="A"));

My problem is, that as soon as my query finds the first QualityAdj value, it only returns that value for the records that match. It doesn't look at any other records. I'm pretty sure it has to do with my where statement and my syntax for passing that as a string, but I'm confused where to put my "'".


Thank you!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:13
Joined
Oct 29, 2018
Messages
21,449
Hi. Are you trying to look up multiple values for the same match or just one? DLookup() can only return one value. If you want all matching values, maybe you could try JOINing the other table in your query instead.
 

Minty

AWF VIP
Local time
Today, 12:13
Joined
Jul 26, 2013
Messages
10,366
Bring the other table (GradeAQualityAdjustment) into your query and directly refer to the fields in it without a join in your criteria.

At the moment your DLookup criteria makes no sense (I've split it out to help see);

DLookUp("QualityAdjustment","GradeAQualityAdjustment",
[CheckStubInfo].[SCC] Between DLookUp("BegQuality","GradeAQualityAdjustment") And DLookUp("EndQuality","GradeAQualityAdjustment")) AS QualityAdj

CheckStubInfo.SCC isn't part of the GradeAQualityAdjustment table so it can't make head nor tail of it.
 

spet

Registered User.
Local time
Today, 06:13
Joined
Oct 5, 2018
Messages
38
Wow! I was overthinking that. Thank you Minty!


This works so much better...
SELECT CheckStubInfo.PatronNo, CheckStubInfo.[BF%], CheckStubInfo.SCC, CheckStubInfo.Bacteria, CheckStubInfo.[Protein%], Round(IIf((350-([CheckStubInfo].[SCC]/1000))>0,(350-([CheckStubInfo].[SCC]/1000))*[Pricing Info].[SCC Premium Price]),2) AS SCCAvg, GradeAQualityAdjustment.QualityAdjustment AS QualAdj
FROM GradeAQualityAdjustment, [Pricing Info] INNER JOIN CheckStubInfo ON [Pricing Info].Date = CheckStubInfo.Date
WHERE ((([Pricing Info].Date)=[CheckStubInfo].[Date]) AND ((CheckStubInfo.Grade)="A") AND ([CheckStubInfo].[Scc] Between [GradeAQualityAdjustment].[BegQuality] And [GradeAQualityAdjustment].[EndQuality]));
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:13
Joined
Oct 29, 2018
Messages
21,449
Hi. Glad to hear you got it sorted out. Good luck with your project.


Thanks for the assist, Minty!
 

Users who are viewing this thread

Top Bottom