Results 1 to 4 of 4
  1. #1
    JAM7007 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    6

    Exclamation Query that excludes rows with criteria in multiple columns

    I am new to Access and have been hitting a wall and seem to be finding nowhere that has this same type of task.

    I have a table(Table 1 ) with 3 columns...

    Table 1




    Click image for larger version. 

Name:	Query Trouble.jpg 
Views:	12 
Size:	18.9 KB 
ID:	12835


    I am trying to run a query that returns Table 1 but excludes rows that meet multiple criteria. I need to return rows that do NOT contain the combination of criteria below

    Criteria

    1) Lot Number - Left([Lot Number],2) = "PT"
    2) Transaction Desc. - "Put-away"


    Basically, i want exclude a "Lot number" starting with "PT" IN COMBINATION WITH a "Transaction Desc" of "Put-away". The goal is for the query to return ROW2 and ROW3 and exclude ROW1.

    ROW1 would be excluded from the query result because it meets both criteria.
    ROW2 and ROW3 would be included because it does not fully meet all criteria.


    Any help on this would be of great help!

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    A Few Methods

    Mathematically, these all achieve the same result.
    The first one subselects all the records to kick out, then kicks them out of the select.
    The second version accepts each record unless it matches both criteria together.
    The third version accepts each records that fails to match either criteria individually.

    Take your Pick:
    Code:
    SELECT (fields)
    FROM MyTable
    WHERE MyKey NOT IN 
       (SELECT T2.MyKey
        FROM MyTable AS T2
        WHERE (( Left(T2.[Lot Number],2)  = "PT")
        AND (T2.[Transaction Desc] = "Put-Away")));
    or
    Code:
    SELECT (fields)
    FROM MyTable
    WHERE NOT 
       ( 
       (Left([Lot Number],2)  = "PT") AND
       ([Transaction Desc] = "Put-Away")
       );
    or
    Code:
    SELECT (fields)
    FROM MyTable
    WHERE 
       (
       NOT( Left([Lot Number],2) = "PT")
    OR NOT([Transaction Desc] = "Put-Away")
       );

  3. #3
    JAM7007 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    6
    Thank you very much, Dal. This have been a great solution and learning process for me and was able to save vast amounts of time. Code 2 seemed to be very effective.

  4. #4
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Happy to oblige. Please mark the thread solved. Top of the page, under "Thread tools".

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 01-02-2013, 11:23 PM
  2. Replies: 1
    Last Post: 08-31-2012, 01:56 PM
  3. Convert multiple rows to columns?
    By NelsonKauley in forum Programming
    Replies: 2
    Last Post: 04-04-2012, 04:59 PM
  4. Replies: 2
    Last Post: 01-02-2012, 06:46 PM
  5. Unmatched with multiple columns and rows
    By sampson20 in forum Programming
    Replies: 1
    Last Post: 04-18-2011, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums