Results 1 to 6 of 6

Thread: [RESOLVED] Simplify this SQL Statement?

  1. #1

    Thread Starter
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Resolved [RESOLVED] Simplify this SQL Statement?

    In the Access Query Designer I am limited to 255 characters in the 'Criteria' field.

    Is there any way to accomplish this with less characters?

    Like "*" & "06-" & "*" And Not Like "*" & "106-" & "*" Or Like "*" & "07-" & "*" And Not Like "*" & "107-" & "*" Or Like "*" & "08-" & "*" And Not Like "*" & "108-" & "*" Or Like "*" & "09-" & "*" And Not Like "*" & "109-" & "*" Or Like "*" & "10-" & "*" And Not Like "*" & "110-" & "*" Or Like "*" & "11-" & "*" And Not Like "*" & "111-" & "*" Or Like "*" & "12-" & "*" And Not Like "*" & "112-" & "*" Or Like "*" & "13-" & "*" And Not Like "*" & "113-" & "*"


    I have values in my table which are like "06-01", "06-02",...."106-01", "106-02", etc.

    I'm trying to get only the values that equal "06" and not "106". Withouth the above criteria, the query returns both "06" and "106", for example, when only "06" is wanted.

    The SQL criteria above works great, but since I'm limited to 255 characters, I cannot get "06-" through "20"... had to stop at "13", save the query, print the report, then change the criteria for pages 14-20.

    Not ideal at all.
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Simplify this SQL Statement?

    I have values in my table which are like "06-01", "06-02",...."106-01", "106-02", etc.
    Firstly, you can cut down the length dramatically by using
    "*06-*" instead of "*" & "06-" & "*"
    "*106-*" instead of "*" & "106-" & "*"

    Secondly, that whole lot can be simplified to this:
    Like "0[6-9]-*" Or Like "1[0-9]-*" Or Like "20-*"
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: Simplify this SQL Statement?

    My friend, you have saved the day. That works perfectly!
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

  4. #4

    Thread Starter
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: Simplify this SQL Statement?

    I am unable to give add to anyone's reputation. It says I must spread some around. I get this message for every person I try to Rate. What gives Moderators?
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Simplify this SQL Statement?

    Quote Originally Posted by jazFunk View Post
    I am unable to give add to anyone's reputation. It says I must spread some around. I get this message for every person I try to Rate. What gives Moderators?
    I'm not sure of the numbers, but you cannot give a rating to the same person within X days, and/or until you have rated Y other people.

    I have a feeling that at the moment X is 10 and Y is 5, but that could be wrong.

    For more info on ratings and reputations, see here.


    By the way, you were lucky that I saw your post... if you want to ask a moderator/admin about site usage, you should generally post in our Forum Feedback forum, which is near the bottom of the list of forums.

  6. #6

    Thread Starter
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: [RESOLVED] Simplify this SQL Statement?

    Thanks for the links and info.

    I suppose it was a bit presumptuous to think a moderator would be reading this post.

    Again, thank you.
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width