Solved

MS Access 2003 query to select a record on multiple conditions

Posted on 2009-04-07
7
279 Views
Last Modified: 2012-05-06
I need  a query to select Field1, Field2, Field3, Field4 and Field5 from every record in Table1 *except* records that meet the following criteria:
- Records in table1 that have a "0" (zero) in Field3, Field4 and Field5.
AND
- also have the first 4 numbers of a 6 digit number in Table1.Field2 match the first 4 numbers of Table2.Field1

Both points (conditions) must be met for the record to be excluded from query results.
0
Comment
Question by:Muskie12
  • 3
  • 2
  • 2
7 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24089858

select *
from tablex
where (field3=0 or field4=0 or field5=0) and left(field2,4)=left(field1,4)
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24089865
if you aare not getting the correct results, post sample data and the expected records you want to see
0
 
LVL 15

Accepted Solution

by:
MNelson831 earned 500 total points
ID: 24089991
2 tables Cap.

select Field1, Field2, Field3, Field4 and Field5 from Table1
where Field3 <> 0 and Field4 <> 0 and Field5 <> 0 and left(Field2,4) not in (Select left(Field1,4) From Table2)

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24090103
and I didn't see  *except* <lol>  
0
 

Author Comment

by:Muskie12
ID: 24090153
capricorn1 - I *thought* your query looked funny but figured it was a case of it being brilliant in its simiplicity so I was trying to experiment with it anyway...

MNelson831 - what do you mean "2 tables Cap."?    Also, I think since your query is selecting the records I want but using the logic of the records I want excluded, I *think* the "and"s in the first part of the WHERE need to be "or"s. I'm just playing with it now.
0
 

Author Comment

by:Muskie12
ID: 24090529
Thanks MNelson831, a couple of slight mods (repl 'and's with 'or's and remove the 'not' gave me the records I was looking for.

SELECT Table1.Field1
FROM COA
WHERE (((COA.JAN)<>0)) OR (((COA.FEB)<>0)) OR (((COA.MAR)<>0)) OR (((Left([Account],4)) In (Select left(Field1,4) From Table2)));
0
 
LVL 15

Expert Comment

by:MNelson831
ID: 24090640
My bad... I read the question as wanting to exclude records that met ALL conitions rather than records that met ANY condition
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now