Results 1 to 6 of 6
  1. #1
    Techno is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2023
    Posts
    31

    [ ] with LIKE not working in WHERE clause

    I don't know what mistake I am doing but here is the scenario-



    SELECT * FROM Table3
    WHERE Column2 LIKE '[a-d]';

    Column2 has a,b,c,d,e,f

    is fetching no records. I have tried using both capital and small letters but it's not working.
    Ideally it should fetch records where Column2 is a,b,c,d.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    Code:
    SELECT Table3.Column2
    FROM Table3
    WHERE (((Table3.Column2)>="a" And (Table3.Column2)<="d"""));
    Or even:
    Code:
    SELECT Table3.Column2FROM Table3
    WHERE (((Table3.Column2) Between "A" And "D"));
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Not clear what you mean.
    Column2 has a,b,c,d,e,f
    All of those characters can be in one record or any record may contain one or more of them? If all in one record then even >="a" And <="g" will return a to f if it's all one string.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Returning to my shop now so will suggest that if the field looks like
    Descr
    a,b
    b,e
    e
    g
    then maybe what you want is Like '[a-f]*'
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Techno is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2023
    Posts
    31
    Thank Bob, your queries worked.
    And Thanks Micron, actually the values are individual letters to signify a group name, so "a" in a row and then "b".

    Wondering if [] are not supported in Access, as Bob suggested BETWEEN worked perfectly.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Wondering if [] are not supported in Access
    I gave you a working example of using [].
    The data
    Descr
    a,b
    b,e
    e
    g
    The result
    Descr
    a,b
    b,e
    e
    The wild card returns single value records as well as multiple so works either way.
    Since your records only contain single values:
    New data

    Descr
    a
    b
    e
    g
    New results (using only Like '[a-f]' so no wild card)
    Descr
    a
    b
    e

    There must be something different about your data if neither of them work for you. If you want that investigated post a zipped copy of your db.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-12-2017, 11:12 PM
  2. SQL Where Clause Not Working
    By Bdenn in forum Queries
    Replies: 12
    Last Post: 05-09-2015, 09:23 AM
  3. Opening Report using WHERE CLAUSE not working
    By babui386 in forum Reports
    Replies: 2
    Last Post: 02-28-2013, 06:15 PM
  4. TOP clause not working
    By fabilewk in forum Queries
    Replies: 5
    Last Post: 08-02-2011, 12:19 PM
  5. Report "WHERE" clause not working
    By rsearing in forum Reports
    Replies: 4
    Last Post: 05-26-2009, 02:07 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