Question regarding and/or Query

  • Thread starter Thread starter Joe C
  • Start date Start date
J

Joe C

I have a query for which I want to create 1 static (mandatory)
condition and 4 optional "or" conditions but can't seem to complete.
Here is the situation:

I want to query records based on a date range Between "x" and "y". No
problem doing this. Now, I want to retrieve only those records within
that date range that have either 1 of 4 characteristics (my 4 "or"
conditions.)

For example, retrieve vendors that purchased within a stated date range
and either purchased product A,B,C or D. (Had to have purchased one of
these products can't be a vendor that did not purchase one of these
products)

Unfortunately, each time I set up the query I am forced in to making
one of the 4 characteristics as a mandatory "And" condition rather than
the 1 mandatory date range and any one of the 4 other conditions.

How can I create a query that says within X-Y date range and has 1 of 4
four possible category's.

Thanks, java
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In SQL view set the WHERE clause to something like this:

WHERE purchase_date BETWEEN [start date] And [end date]
AND product_code IN ('A','B','C','D')

The IN () predicate is the same as using:

WHERE purchase_date BETWEEN [start date] And [end date]
AND (product_code = 'A' OR product_code = 'B' OR product_code = 'C' OR
product_code = 'D')

Note the parentheses around the multiple OR expressions.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRK66doechKqOuFEgEQKiagCfZnBGGl0IHi+iqWvy3gtlZeLWI2cAoJVa
z7WFXHFM15amFDYPN2Duh0sg
=Gapa
-----END PGP SIGNATURE-----
 
Thank you! This is what I was looking for!!!

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In SQL view set the WHERE clause to something like this:

WHERE purchase_date BETWEEN [start date] And [end date]
AND product_code IN ('A','B','C','D')

The IN () predicate is the same as using:

WHERE purchase_date BETWEEN [start date] And [end date]
AND (product_code = 'A' OR product_code = 'B' OR product_code = 'C' OR
product_code = 'D')

Note the parentheses around the multiple OR expressions.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRK66doechKqOuFEgEQKiagCfZnBGGl0IHi+iqWvy3gtlZeLWI2cAoJVa
z7WFXHFM15amFDYPN2Duh0sg
=Gapa
-----END PGP SIGNATURE-----


Joe said:
I have a query for which I want to create 1 static (mandatory)
condition and 4 optional "or" conditions but can't seem to complete.
Here is the situation:

I want to query records based on a date range Between "x" and "y". No
problem doing this. Now, I want to retrieve only those records within
that date range that have either 1 of 4 characteristics (my 4 "or"
conditions.)

For example, retrieve vendors that purchased within a stated date range
and either purchased product A,B,C or D. (Had to have purchased one of
these products can't be a vendor that did not purchase one of these
products)

Unfortunately, each time I set up the query I am forced in to making
one of the 4 characteristics as a mandatory "And" condition rather than
the 1 mandatory date range and any one of the 4 other conditions.

How can I create a query that says within X-Y date range and has 1 of 4
four possible category's.
 
Back
Top