We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How do I search for ' in SQL query?

stressfreewebs
on
Medium Priority
219 Views
Last Modified: 2012-05-07
Hi There,

I need to search for a name in a database - so far so good. However, when I come up with a name like O'Leary to search for, this causes a problem as obviously the ' character signals the end of the string to be searched for. My SQL code is below, how can I modify this to work as I need it to?

I am working in ASP / VBScript.

Many thanks,

Dan
SELECT * FROM Artists WHERE aName = 'O'Leary' AND aStatus = 1

Open in new window

Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
You could also try to to escape the ' like:

SELECT * FROM Artists WHERE aName = 'O\'Leary' AND aStatus = 1

Author

Commented:
Brilliant and thanks for the quick response...I should have guessed that actually, but couldn't find it on Google so thought it must be something complex!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.