how to search for % string in your query?

  • guys,

      using select statement how can i search for a field that contains the '%' string? It gives me an error since the search parameter itself is % used in the like statement.

     

    thanks

     

    - Satish

  • From BOL under escape Characters

    You can search for wildcard characters. There are two methods for specifying a character that would ordinarily be a wildcard:

    • Use the ESCAPE keyword to define an escape character. When the escape character is placed in front of the wildcard in the pattern, the wildcard is interpreted as a character. For example, to search for the string 5% anywhere in a string, use:
      WHERE ColumnA LIKE '%5/%%' ESCAPE '/'

      In this LIKE clause, the leading and ending percent signs (%) are interpreted as wildcards, and the percent sign preceded by a slash (/) is interpreted as the % character.

    • Use square brackets ([ ]) to enclose the wildcard by itself. To search for a dash (-), rather than using it to specify a search range, use the dash as the first character inside a set of brackets:
      WHERE ColumnA LIKE '9[-]5'

    • hth

    • Tal MCMahon


    Kindest Regards,

    Tal Mcmahon

  • Thanks Tal. That worked like a charm !

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply