September 1st, 2008

LIKE (Matching to a Pattern), Part 3 of 3

Posted by admin in D. WHERE Clause

> Sometimes you may wish to include an underscore or a percent sign in the LIKE comparison pattern.
> You need a way to tell SQL that the underscore or percent sign is not to be used as a wildcard character.
> You can do this by typing an escape character just prior to the character you wish SQL to take literally.
> You can choose any character as the escape character, as long as that character does not appear in the string you are testing, as shown:

> This statement will look for the percent sign (%) anywhere in the NOTES.
> The first % says there may be any number of characters ahead of the percent sign.
> The next #% says that it is looking for the percent sign and it is not a wildcard character because it has the escape character ahead of it. The escape character must be defined as shown above.
> The last % says that there may be any number of characters after the percent sign.

> Access does not support the ESCAPE clause. Instead it uses brackets [ ] for an exact character matches on a single chracter. In Access WHERE NOTES LIKE ‘%[%]%’ does the same as the example shown above.
> SQL Server expands on the Microsoft use of brackets. A range of a single character match can be specified and the [^] character means not. Examples:

‘[a-g]et’ matches ‘bet’, & ‘get’, but not ‘let’.
‘[bln]et’ matches ‘bet’, ‘let’, & ‘net’, but not ‘get’.
‘ma[^t]%’ matches ‘man’, & ‘maverick’, but not ‘mat’, or ‘material’.

4 Responses to ' LIKE (Matching to a Pattern), Part 3 of 3 '

Subscribe to comments with RSS or TrackBack to ' LIKE (Matching to a Pattern), Part 3 of 3 '.

  1. Ty Gess said,
    on January 4th, 2010 at 8:54 am

    Hi, probably this posting is off topic but anyhow, I have gone surfing about your blog and it seems genuinely neat. It is obvious you know the topic and you seem fervent about it. I

  2. Backlinks said,
    on January 13th, 2010 at 6:16 pm

    You made some Good points there. I did a search on the topic and found most people will agree.

  3. on January 22nd, 2010 at 3:19 am

    It amazes me to know that you have such a vast knowledge about this subject. Personally I think that this blog would be an eye opener to most of its readers

  4. on January 24th, 2010 at 4:41 am

    I liked reading your post. I am an SEO and so i love reading good stuff on this subject.

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: