Solved

How do I search for ' in SQL query?

Posted on 2009-07-02
3
195 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

0
Comment
Question by:stressfreewebs
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24761987
SELECT * FROM Artists WHERE aName = 'O''Leary' AND aStatus = 1
0
 
LVL 5

Expert Comment

by:mallcore
ID: 24762007
You could also try to to escape the ' like:

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

Author Closing Comment

by:stressfreewebs
ID: 31599121
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!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question