?
Solved

How do I search for ' in SQL query?

Posted on 2009-07-02
3
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 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