Results 1 to 4 of 4
  1. #1
    russdwright is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    30

    Queries meant to limit data end up adding data to query

    I have a single table created from an Excel import (yeah, yeah, I know ... data normalization, etc. ... Doubt that is causing this issue) that I am processing multiple queries on. The idea is for each query to further drill down and then show the data the meets those specific criteria.

    Example:
    - Total Count = table.field <> "Value"
    - Total Count handled by group x = former query + table.field2 = "Value2"
    - Etc.

    Once I get further down into my queries, the filters increase. The goal is to account for all of the entries and not have repeated entries as I drill down. The problem is, as the queries become more detailed/complex, I run into issues where upon running the query I start seeing records that appeared in earlier queries. In fact, I had to take one query that previously used a LIKE constraint and, after getting updated information on the criteria to use, had to change it to separate queries for each single criteria rather than using ="Value1" OR "Value2" OR "Value x" or Like "Value*" AND <> ("Value X" AND "Value Y") as my arguments. Either time I tried one of these, the results included data that was already in the previous queries I had created.

    Is there some kind of limitation to Access in terms of query length that is making this happen? I looked at the SQL Statement of one of these more complex queries and it was less than 600 characters. I have tried both building new queries from scratch as well as building queries off of existing ones and end up with the same result.



    Unfortunately, this is for work and they are picky about confidential information, so I cannot share the file. I may be able to share the queries, if you are willing to deal with me changing the names of the fields being used.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Parentheses are critical when mixing OR and AND operators.

    All these criteria are for one field? This will not work. Probably need to utilize IN() or NOT IN() somewhere and maybe even subqueries.

    Really need to provide sample data and sample desired result. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    IF the criteria applies to one field, you might have success with UNION SELECT DISTINCT?
    To create sample data, you could copy a table and use update query to modify fields to D.Duck, M. Mouse... or create field aliases and save that query as a table. Maybe not entirely suitable, but no doubt you get the idea.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    russdwright is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    30
    Using IN/NOT IN took care of the issue! Thanks!

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

Similar Threads

  1. Replies: 4
    Last Post: 02-14-2014, 11:09 AM
  2. Replies: 3
    Last Post: 12-19-2011, 11:18 AM
  3. Replies: 5
    Last Post: 04-06-2011, 01:54 PM
  4. Adding data to tables using queries
    By HunterEngineeringCoop in forum Queries
    Replies: 3
    Last Post: 10-28-2010, 12:42 PM
  5. Replies: 4
    Last Post: 02-08-2010, 11:17 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