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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Grid Help - Combining AND + OR

Status
Not open for further replies.

ProjectExplorer

Programmer
Mar 22, 2002
95
GB
I have four fields in a query:

Date Sent
APacks
BPacks
CPacks
DPacks

I need to construct a query where:

Date Sent = Is Null

AND ANY ONE OF THE FOLLOWING IS TRUE:

APacks = Not Is Null
OR
BPacks = Not Is Null
OR
CPacks = Not is Null
OR
DPacks = Not Is Null

How do I do this? Basically how do you construct and query using a comination of AND + OR. I'm not strong on SQL so need to use the query grid.

Any help appreciated.
 
I assume I have to run two queries

qryOne to isolate all records where Date Sent is Null

Then

qryTwo to check whether there is a value in APacks or BPacks or CPacks or DPacks

If there is a way of running this as one query it would be useful as I want to copy the resulting SQL straight into VBA code.

Thanks
 
where Date Sent Is Null

AND
(
APacks Not Is Null
OR
BPacks Not Is Null
OR
CPacks Not is Null
OR
DPacks Not Is Null
)

note: no equles
 




When you use boolean logic that contains OR operators, you must be certain that you EXPLICITLY delimit your AND and OR statements with parehtheses that ensures the logic you intend.

Note that...
Code:
Where A And B OR C
is ambiguous.

Is it???
Code:
Where A And (B OR C)
or is it???
Code:
Where (A And B) OR C
Either one is syntactically correct, but the LOGIC is different and will yield different results.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
You asked for query grid:[tt]
field: Date Sent APacks BPacks CPacks DPacks
criteria: null not null
or: null not null
or: null not null
or: null not null[/tt]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks to every one for your help - very much appreciated.

PHV - Brilliant, thanks - I have learnt something new.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top