Solved

How do I search for ' in SQL query?

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now