Need help with a query...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I had a table with services information for each person. The table has a
member or ID number and several check box fields (yes/no) to show what
services this person has. Then there is a query to show this information by
ranges with the Between [date1] And [date2].
Now I need a query like that by dates, showing only the persons with marked
check boxes
Thank you all, my friends
 
Hi,


SELECT PeopleID, DateTime
FROM myTable
WHERE service1 OR service2 OR service3 OR ... OR serviceN
GROUP BY DateTime, PeopleID



where serviceX are the name of your "several" check box fields,

and DateTime is the field for the dates.




Hoping it may help,
Vanderghast, Access MVP
 
I had a table with services information for each person. The table has a
member or ID number and several check box fields (yes/no) to show what
services this person has. Then there is a query to show this information by
ranges with the Between [date1] And [date2].
Now I need a query like that by dates, showing only the persons with marked
check boxes
Thank you all, my friends

That design is not the best: storing data - services - in fieldnames
is not properly normalized and will cause problems down the road. What
if you need to add two new services? You'll need to restructure your
Table, and all the Forms, Queries and Reports which reference the
table!

If you have a many (people) to many (services) relationship, consider
instead using THREE tables: People, Services, and ServicesUsed. This
latter table would have the PersonID, ServiceID, and possibly other
fields concerning this person's use of this service.

But to answer your question - if you want to retrieve only those
records for which there is at least one True value for any service,
use OR logic. In the query grid put True under each checkbox, *on a
different line* for each; you'll also need to copy the BETWEEN
criterion onto every one of the lines that you use. The SQL view would
be

.... WHERE tablename.datefield BETWEEN [date1] AND [date2] AND
(Service1 OR Service2 OR Service3 OR Service4 OR Service5)

which will in fact be more efficient than the mess you'll get from the
query grid using my suggestion above!

John W. Vinson[MVP]
 
This works very good. Thank you for helping me with that.

John Vinson said:
I had a table with services information for each person. The table has a
member or ID number and several check box fields (yes/no) to show what
services this person has. Then there is a query to show this information by
ranges with the Between [date1] And [date2].
Now I need a query like that by dates, showing only the persons with marked
check boxes
Thank you all, my friends

That design is not the best: storing data - services - in fieldnames
is not properly normalized and will cause problems down the road. What
if you need to add two new services? You'll need to restructure your
Table, and all the Forms, Queries and Reports which reference the
table!

If you have a many (people) to many (services) relationship, consider
instead using THREE tables: People, Services, and ServicesUsed. This
latter table would have the PersonID, ServiceID, and possibly other
fields concerning this person's use of this service.

But to answer your question - if you want to retrieve only those
records for which there is at least one True value for any service,
use OR logic. In the query grid put True under each checkbox, *on a
different line* for each; you'll also need to copy the BETWEEN
criterion onto every one of the lines that you use. The SQL view would
be

.... WHERE tablename.datefield BETWEEN [date1] AND [date2] AND
(Service1 OR Service2 OR Service3 OR Service4 OR Service5)

which will in fact be more efficient than the mess you'll get from the
query grid using my suggestion above!

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top