SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to look for wildcards in the database

    Hello

    I know that the % and _ wildcards can be used in conjunction with LIKE to perform powerful queries.
    I would like to be able to look for these letters as part of my query though.
    For example, If I look for the letter %, then the entry '5%' should be found.

    Similarly for the letter _
    if I look for _ then it should find the entry 'an underscore is _'

    Can anyone tell me how I can escape these special wildcards in my search?

    regards

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to use the escape character like so:

    \_ or \%

  3. #3
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so if I look for:
    %\%%
    it will find anything that contains a '%' ?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    find an underscore --

    ... where foo like '%^_%' escape '^'

    find a percent sign --

    ... where foo like '%?%%' escape '?'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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