Searching for a wildcard character.

  • Gday,

    I have hit upon a problem that I have never seen before in my years of working with SQL Server, its actually rather embarrasing! Anyway, I need to search for SQL's wildcard characters, ie '_' and '%'. Is there anyway to make them into a literal?

  • They will always be treated as a literal unless used in wilcard searching with LIKE and PATINDEX in which case you need to 'ESCAPE' them, ie

    LIKE '%[%]%'

    LIKE '%[_]%'

    or

    LIKE '%\%%' ESCAPE '\'

    LIKE '%\_%' ESCAPE '\'

    or

    PATINDEX('%[%]%',column)

    PATINDEX('%[_]%',column)

    Look up "Pattern Matching in Search Conditions" on BOL for more info

    Far away is close at hand in the images of elsewhere.
    Anon.

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

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