Results 1 to 5 of 5

Thread: Quick question about SQL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    U.S.A.
    Posts
    75
    Just a quick question...

    I am building an SQL statement to pull all values out of a database that begin with the letter S and over...I wrote something like:

    Code:
    "SELECT * FROM Database WHERE Partnumber >= 'S'"
    However this statement does not include Partnumbers such as S-2000 or even S1234.

    Then I thought of adding an ! to the statement so it would include these values:

    Code:
    "SELECT * FROM Database WHERE Partnumber >= 'S!'"
    This would produce the results I wanted....I was just wondering if there was a better way of doing this...without tacking on the !.

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Use the LIKE statement with a wildcard ( % ) for character searching:

    SELECT * FROM Database WHERE Partnumber LIKE 'S%'

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    And, if you're using Access and the "%" wildcard doesn't work, try "*" in its place

  4. #4
    Member
    Join Date
    Aug 2000
    Posts
    51

    Lightbulb

    Try using the like operator with the % and _

    the % stands in for a substring of 0 or more characters

    example

    select * from table where string like 'S%'

    the _ stands for exactly one character

    example

    select * from table where string like 'S__'

    I know the statement with like % will probably work for you. I've had that work with Microsoft SQL server. I don't have any experinece using the underscore but from what I've read in SAMS publishing SQL Unleashed that should work.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    U.S.A.
    Posts
    75
    The LIKE statement with operator works nicely to retrieve all of the S items nicely. I thank you all for the help.

    I just added it with an OR to my original statement to create the desired results.

    Code:
    SELECT * FROM Database WHERE Partnumber LIKE 'S%' OR Partnumber >= 'S'
    Thanks again

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