Aliaspooryorik
ColdFusion ORM Book

Search for % sign in SQL.

This one came up recently so I thought I'd blog it.

MS SQL server uses the percentage sign (%) as a wildcard when you use the like operator. For example:


SELECT
post_id
, post_title
FROM Posts
WHERE post_title LIKE '%100%'

This will return all the posts that have 100 in the post title, regardless of whether it is "Made with 100% ColdFusion" or "Over 100,000 cats can't be wrong".

So what if you want to search for the percentage sign? You need to escape it like this:


SELECT
post_id
, post_title
FROM Posts
WHERE post_title LIKE '%100[%]%'

This will find all posts that contain "100%" in the title of the post.

  • Posted in:
  • SQL

1 comment

  1. Thanks! This was very helpful!

    Comment by Melanie Rogers – January 11, 2012

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts