Results 1 to 5 of 5

Thread: LIKE statement: not exact match DB search

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2
    I am trying to search a database in a not exact manner and know that I can use the like statement to help with this search of the database but do not know exactally how to do this. Any help?

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Try:

    SELECT * FROM TABLE_NAME WHERE COLUMN_NAME LIKE '*CRITERIA*'


    TABLE_NAME is name of the table that you want to extract the data. Insert your table name here.

    COLUMN_NAME is the name of the column. Insert your column name here.

    * is a wild card character CRITERIA is the data you want and another * wildcard at the end.

    For example: Say my table is named CONTACTS and the column is called NAME(contains first and last separated by a space) then I would use:

    SELECT * FROM CONTACTS WHERE NAME LIKE 'John*'

    This will return all names beginning with John, the last name is the wildcard.


    Psyrus

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    The wildcards depend on what Database you are running the Query on.

    If you are using SQL Server then the wildcards are :

    % - (Percent) Match none or more characters
    _ - (Underscore) Match EXACTLY one character


    LIKE '%ed' will find : (ends in)

    fred
    bed

    LIKE '%ed%' will find : (contains)

    fred
    bed
    medical

    LIKE '_ed' will find : (3 letter word, any 1st letter)

    bed
    ted
    wed

  4. #4
    Guest

    Thumbs up Or you could use something like

    Code:
    sName = "John"
    rs.movefirst
    Do
      rs.FindNext("Name Like '*" & sName & "*'")
      If rs.EOF Then
         MsgBox "Damn got that one Wrong"
         Exit Do
      End If
      '
      ' Is this the record you want sort of testing
      '
      Exit Do
    Loop
    ...or something similar. Psyrus answer is good if you want to extract all records from a Table which match a criteria for processing. The above code is good if you are seeking a single instance.

    Hope this Helps

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2

    Thanks

    Thanks for your help Psyrus, Gen-X, and Jethro. I went with the approach Gen X submitted. I forgot to mention that it was a SQL database. Hope I am able to get the same levle of quality responses in the future.

    Nixoid

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