Results 1 to 7 of 7
  1. #1
    RoyS is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2016
    Posts
    3

    Remove records if it contains with any of the following value

    i am trying to exclude records when the field contains with any of the text.


    For example, John has the following codes: (SOY, NOC, NME, NMA); Mary as the following codes: (NMA and NOC); and Joshua has the following codes: (NMA)

    I want to exclude records that contain either SOY or NOC. The correct result should only show Joshua. When i used Not in on the query, it does not give the correct result.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Show us your current SQL statement

  3. #3
    RoyS is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2016
    Posts
    3
    SELECT testing.[first name], testing.[last name], testing.yea, Sum(testing.amt) AS SumOfamt, testing.pdim, [address 2].address, [address 2].city, [address 2].state, [address 2].zip, exclusion.exclusion
    FROM (testing INNER JOIN [address 2] ON testing.pdim = [address 2].pidm)
    INNER JOIN exclusion ON [address 2].pidm = exclusion.pidm
    GROUP BY testing.[first name], testing.[last name], testing.yea, testing.pdim, [address 2].address, [address 2].city, [address 2].state, [address 2].zip, exclusion.exclusion
    HAVING (((testing.yea)>="2013") AND ((Sum(testing.amt))>=50) AND ((testing.pdim) Like "z*") AND ((exclusion.exclusion) Not In ("NOC","SOY")));

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    it does not give the correct result.
    does not help us help you - for the future explain the you are getting as well as the result you expect. So we have to speculate what the problem is and offer a number of possible solutions

    three of your criteria should be in the where part of the code

    ...
    ...
    WHERE testing.yea>="2013" AND testing.pdim Like "z*" AND exclusion.exclusion Not In ("NOC","SOY")
    GROUP BY testing.[first name], testing.[last name], testing.yea, testing.pdim, [address 2].address, [address 2].city, [address 2].state, [address 2].zip, exclusion.exclusion
    HAVING Sum(testing.amt)>=50

    I presume that John has 4 records (one each for SOY, NOC, NME, NMA), Mary 2 and Joshua 1

    Also having a field name the same as the table name will cause issues at some point - probably this one since the syntax otherwise looks OK.

    if John has one record with an exclusion field value of "SOY, NOC, NME, NMA", then your query won't work. Instead, since your data is not normalised you need

    ...AND (exclusion.exclusion Not like "*NOC*" OR exclusion.exclusion Not Like "*SOY*")

    Finally, if your exclusion field is a multivalue field, then you need to refer to the .value property of the field

    .... AND exclusion.exclusion.value Not In ("NOC","SOY")

  5. #5
    RoyS is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2016
    Posts
    3
    thank you for the feedback. i put this sample data quickly and didn't follow the best practice.
    Your assumption is correct: John has 4 records (one each for SOY, NOC, NME, NMA), Mary 2 (NOC, NME) and Joshua 1 (NMA)
    i would like to know on Access, what to put in the criteria to remove record contains any of these value (SOY, NOC). Attached is the print screen.Click image for larger version. 

Name:	prtsc.png 
Views:	10 
Size:	196.5 KB 
ID:	26489

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    One other point: it doesn't make any sense having a criteria of
    Code:
    testing.yea >= "2013"
    "2013" is a TEXT string. The "Greater than or equal to" condition won't work/doesn't make sense with a text string.

    If the data stored in the field "testing.yea" are years, I would suggest the data type should be Integer or Long Integer instead of Text.

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    would like to know on Access, what to put in the criteria to remove record contains any of these value (SOY, NOC).
    look at my first suggestion. If you want to see or edit the sql your query generates, click on the View option at the top left on the ribbon and select SQL, or click on SQL to the bottom right of your screen.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-20-2015, 01:09 PM
  2. get and remove records form recordset
    By xopherira in forum Programming
    Replies: 6
    Last Post: 11-06-2015, 02:40 PM
  3. Replies: 3
    Last Post: 03-22-2014, 04:32 PM
  4. Remove deleted records
    By amerifax in forum Access
    Replies: 4
    Last Post: 10-17-2012, 03:26 AM
  5. remove records from table
    By bird66 in forum Queries
    Replies: 1
    Last Post: 06-02-2011, 09:34 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