Solved

How do I search for ' in SQL query?

Posted on 2009-07-02
3
191 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
Comment Utility
SELECT * FROM Artists WHERE aName = 'O''Leary' AND aStatus = 1
0
 
LVL 5

Expert Comment

by:mallcore
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

8 Experts available now in Live!

Get 1:1 Help Now