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

Need to filter a query 2 ways

Status
Not open for further replies.

Fozzy9767

Technical User
Jun 12, 2006
58
US
I have a query that returns a bunch of data by a unique ID. I need to filter it for a report so I get a total that is a calculation of certain ID's. My problem is I need to get 2 different subsets, while leaving out 2 sub-sub sets of one of my sub sets. Here is an example: My UID field is populated by numbers in this format 30032001005254 or 300320070010001 or 30052005001008. There are about 200 separate distinct entries. Here is what I need returned: I need to get a sum for all fields where my UID is LIKE 30032001* OR 30032007*, but also NOT LIKE 30032001007* OR 30032001014*. I can get the first part fine but cannot get it to exclude the second pair. Is this a syntax problem or can I not do this all at once?
Thanks for any help, Ken.
 
Not sure to have well understood the issue, thus just a guess (SQL snippet):
WHERE (UID LIKE '30032001*' OR UID LIKE '30032007*') AND UID NOT LIKE '30032001007*' AND UID NOT LIKE '30032001014*'

Another way:
WHERE Left(UID,8) IN ('30032001','30032007') AND Left(UID,11) NOT IN ('30032001007','30032001014')

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That did it! Thanks. The design grid kept putting all those extra () around everything, When I typed it in in your simplified format it gave me the correct totals.
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top