By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

search for special character

P: 144

how to search a string in a table that contain a special character ?

for example i want to search fo a string "D'Crepes" in a field of a table.
i've tried using the following sql from vb .net

Expand|Select|Wrap|Line Numbers
  1. select name from menu where name like '%D'Crepes%'
but since ' is a special character, i got an error. is there anyway to do this, like using \ in mysql?

Thank you,
Nov 30 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 8,638
Expand|Select|Wrap|Line Numbers
  1. SELECT Name From Menu Where InStr([Name],"D'Crepes") > 0;
Nov 30 '08 #2

Expert 2.5K+
P: 3,072
An alternative is to use the [ and ] around the special character like:

Expand|Select|Wrap|Line Numbers
  1. select name from menu where name like '%D[']Crepes%'
These [ and ] can also be used to select a range for one character, e.g. a to k by using "[a-k]"

Nov 30 '08 #3

Expert 5K+
P: 8,638
Nico makes an excellent point, just to add to what Nico has said, you can also search for characters outside of the Range by using the '!' within the defined Range. The following Query will return all Last Names that do not begin with the characters a thru k:
Expand|Select|Wrap|Line Numbers
  1. SELECT Employees.LastName
  2. FROM Employees
  3. WHERE Employees.LastName Like "[!a-j]" & "*";
Nov 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.