Escape single quote using LIKE statement

  • Hi Folks

    I'm trying to use the LIKE operator to search a string to look for a single quote.

    How do I escape the ' char in the LIKE clause

    IE LIKE '%'%'

    Thanks in advance

     

    Stuart

  • Stuart

    Like this:

    CREATE

    TABLE #John (John char(10))

    INSERT INTO #John VALUES ('1234567890')

    INSERT INTO #John VALUES ('!"£$''^&*()')

    SELECT

    * FROM #John

    WHERE John LIKE '%''%'

    DROP

    TABLE #John

    Result set:

    John

    ----------

    !"£$'^&*()

    John

  • John,

    Great stuff. Thanks for your help.

    Stuart

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

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