Search in SQL for a value containing a ‘ character


So, you are stuck with a problem…

You need to find User names that are stored in the DB Users table, and that contain the apostrophe character. (eg. Susan D’Souza)

How do you go about it?

You know the LIKE keyword has to be used somewhere. But, when you add the apostrophe character in the LIKE criteria, the query gives an error (as displayed below) on execution.
SQL LIKE query with apostrophe

Error for SQL LIKE query with apostrophe

It took a while for my colleague and I to find the resolution to this, but thanks to the world wide web, we did find it. 😀

And now I am writing it down here for the benefit of any one else who stumbles across this entry while searching online for the solution. (and of course, for my future reference)

And it’s a very simple solution –
Instead of just one apostrophe character, write 2 of them consecutively in the LIKE criteria.

An Example is given below-

>> SELECT * FROM Users where UserName like ‘%D”Souza%’

The above query will give you the list of all the users that have “D’Souza” in their name.

Happy Querying and see you soon… 🙂

Find links to your website through Google


Thanks to a post in another blog (http://blog.nerdstogeeks.com/2009/06/track-links-to-your-site-from-google.html), I learnt a new thing yesterday.

You can find out all the references to your website in the world wide web by this simple trick.

Just go to Google search, type in “link: ‘Your website URL’“, and press Enter.

Google will list out all the links to your website URL from where people can visit your page. Nice, huh?