Solved

SQL - need to search for data/name with single quote

Posted on 2009-03-31
7
315 Views
Last Modified: 2012-05-06
Simple query statement that I am stumbling with...  I have a dealerName column that has records with single quotes as data  

eg.  Vann's

The form bombs without any string cleaning to deal with the single quote.  

I created this to deal with it... but it still returns 'no records found'
function cleanQuote(searchTerm)

	dim preQuote

	dim postQute

	postQuote  = replace(searchTerm,"'","'")

	cleanQuote = postQuote

end function

Open in new window

0
Comment
Question by:jweissdandm
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 105 total points
ID: 24029561
Convert to two single quotes when you save and when you query:
postQuote  = replace(searchTerm,"'","''")
0
 
LVL 4

Expert Comment

by:amazingwolf1
ID: 24029583
try to search like this:
select * from MyTable where ColumnName = 'ddd''d'

Note that to search for a string with a single quote in MSSQL you should double the single quote ('').

HTH

0
 
LVL 2

Author Comment

by:jweissdandm
ID: 24029707
apresto...

Isn't my code doing the same thing?  If the columnData has a single quote, how does it return the rows if the columnData is replace with 2 single quotes?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Assisted Solution

by:amazingwolf1
amazingwolf1 earned 100 total points
ID: 24029761
in sql server, the T-SQL syntax uses single quote as part of the syntax. to allow you to still use single quotes, the syntax requires to mark a single quote inside a column as a double single quote.

So your replace should be:
replace(searchTerm,"'","''")


0
 
LVL 2

Author Closing Comment

by:jweissdandm
ID: 31564853
Thanks gentlePeople
0
 
LVL 23

Expert Comment

by:apresto
ID: 24030571
Thanks for explaining amazingwolf1:) i was a little busy
Glad we could help
Apresto
0
 
LVL 4

Expert Comment

by:amazingwolf1
ID: 24036715
Thank you, aspresto - hope we will ALL stay as busy as we can :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

706 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

19 Experts available now in Live!

Get 1:1 Help Now