Results 1 to 13 of 13
  1. #1
    etsoft is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    6

    Querie not working on the OR part

    Hello,

    i have the following querie :

    SELECT TOP 16 Activities.ID, Activities.WPID, Activities.ActivityID, Activities.ActivityDesc, Activities.progress, Activities.kritisch, Activities.Vergunning, Activities.Vergunningdatum, Activities.geplande_datum, Activities.TypeVergunning, Activities.Groep, Activities.Plankaart, Activities.VergunningVerwerkt, Activities.Werkpakket, Activities.selectie, Activities.startdatum, Activities.einddatum, Activities.gewijzigd, Activities.datum, Activities.Repsonibility, Activities.LA, Activities.Area FROM Activities
    WHERE (((Activities.WPID)=43300) AND ((Activities.progress)<100) AND ((Activities.Plankaart)="plk02")) OR (((Activities.WPID)=43300) AND ((Activities.progress)=100) AND ((Activities.Plankaart)="plk02") AND ((Activities.gewijzigd)=True));




    In the WHERE part the are two parts, the data of the second part is not showing.Both must apply. What am i missing here?
    It is a single table, no joins.


    The difference is in the 'progress' field and additional the 'gewijzigd' field.

    Thanks in advance
    Erwin

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,427
    Maybe this simplification?
    Code:
    WHERE ((Activities.WPID=43300 AND Activities.progress<100 AND Activities.Plankaart="plk02") OR (Activities.WPID=43300 AND Activities.progress=100 AND Activities.Plankaart="plk02" AND Activities.gewijzigd=True));
    You could also try it with just the second part to make sure that part works, then combine with the OR
    Last edited by davegri; 07-30-2019 at 03:02 PM. Reason: fromat and addl

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,448
    you can also rearrange the criteria - although the query grid will probably arrange it back again when you save it

    WHERE Activities.WPID=43300 AND Activities.Plankaart="plk02" AND (Activities.progress<100 OR (Activities.progress=100 AND Activities.gewijzigd=True))

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Is this a saved query or a sql statement in code?
    If the latter change the double quotes "plk02" to single quotes 'plk02’
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    etsoft is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    6
    No both suggestions does not show the 100 and true situation, only the first part. It will be used in code so saving the querie will not be nescesary.
    The double quotes are working correctly, in code the will be changed of course.
    Other sugesstions?

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,448
    I presume your data does contain a progress value of 100 (and not a double with 99.999999) and gewijzigd of true


    The criteria seems straightforward enough to me suggest provide some example data and the result you require in case my understanding is incorrect. or upload some sample data in a table

  7. #7
    etsoft is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    6
    Hereby and csv file with all relevant data, the red lines should me excluded in the querie

    Click image for larger version. 

Name:	2019-07-31 15_38_20-testSql.csv - Excel.png 
Views:	8 
Size:	11.5 KB 
ID:	39248
    Attached Files Attached Files

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,448
    your gewijzigd is text, not a boolean in the example you sent

    ONWAAR I believe is false so neither of those two records would be returned

    what does get returned is ID 184280 which meets the 'OR' part of your criteria

    So the criteria is doing what it is supposed to be doing. If that is not what you want, clarify what you do want with examples

    This is the sql I used
    Code:
    SELECT TestSql.*
    FROM TestSql
    WHERE (((TestSql.[progress])<100) AND ((TestSql.[WPID])=43300) AND ((TestSql.[Plankaart])="plk02")) OR (((TestSql.[progress])=100) AND ((TestSql.[WPID])=43300) AND ((TestSql.[Plankaart])="plk02") AND ((TestSql.[gewijzigd])='WAAR'));
    and this is the result

    ID WPID Plankaart gewijzigd progress
    184210 43300 Plk02 ONWAAR 0
    184221 43300 Plk02 ONWAAR 0
    184247 43300 Plk02 ONWAAR 0
    184253 43300 Plk02 ONWAAR 0
    184255 43300 Plk02 ONWAAR 0
    184280 43300 Plk02 WAAR 100
    184291 43300 Plk02 ONWAAR 0
    184292 43300 Plk02 ONWAAR 0

  9. #9
    etsoft is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    6
    Yes thank you, this is the correct one.
    In the conversion i made the 'gewijzigd' field was converted to text but the original field was Boolean.

    Again thanks.

    Erwin

  10. #10
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    (((TestSql.WPID)=43300) AND ((TestSql.Plankaart)="plk02") AND ((TestSql.progress)<100)) OR (((TestSql.WPID)=43300) AND ((TestSql.Plankaart)="plk02") AND ((TestSql.progress)=100) AND ((TestSql.gewijzigd)=True));

    substitute in your table name.

    This is assuming

    WAAR means true
    ONWAAR means false

    I got the same result from both queries (my test and and your query criteria), both are correctly excluding the two records you highlighted in red.

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,448
    I see absolutely no difference between the criteria in the original post or mine or rpeare's query (other than the boolean/text swap)

    So what is all the fuss about?

  12. #12
    etsoft is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    6
    Somehow, the original code did not work and the post from you did, perhaps i did not copy it right.
    Did you all try it in Access or some other software?

  13. #13
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,448
    all done in access

    Somehow, the original code did not work and the post from you did, perhaps i did not copy it right.
    other than changing the table name and the boolean/text swap, the criteria per your original post also worked

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

Similar Threads

  1. Replies: 5
    Last Post: 02-27-2016, 09:46 AM
  2. Iif not working as a part of criteria
    By crobaseball in forum Access
    Replies: 8
    Last Post: 05-26-2015, 07:32 PM
  3. How Can export Large table part by part
    By shabar in forum Import/Export Data
    Replies: 2
    Last Post: 02-04-2013, 06:29 AM
  4. Last Part of code not working
    By mejia.j88 in forum Programming
    Replies: 19
    Last Post: 02-22-2012, 12:36 PM
  5. Replies: 1
    Last Post: 10-25-2011, 09:47 PM

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