Searching for % within a string

  • Hello,

    Another probably very simple question so I apologise in advance :blink:

    I have a string that contains lots of characters and I want to find % within the string to only bring back the rows that contain this character. However the query looks like this AND Sessions LIKE '%%%'

    and it doesnt work.......

    Does anyone know how to actually look for a wildcard in the data using the wildcard?

    Thanks

    Debbie

  • AND Sessions LIKE '%'+char(37)+'%'

  • Thanks for that!!!

    Brilliant :w00t:

  • LIKE '%/%%' ESCAPE '/'

    Means that the character after the / is treated as a literal, not as a wildcard.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • also

    AND CHARINDEX('%',Sessions)>0

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537

Viewing 5 posts - 1 through 4 (of 4 total)

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