Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

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

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
jweissdandm
Asked:
jweissdandm
  • 3
  • 2
  • 2
2 Solutions
 
aprestoCommented:
Convert to two single quotes when you save and when you query:
postQuote  = replace(searchTerm,"'","''")
0
 
amazingwolf1Commented:
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
 
jweissdandmAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
amazingwolf1Commented:
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
 
jweissdandmAuthor Commented:
Thanks gentlePeople
0
 
aprestoCommented:
Thanks for explaining amazingwolf1:) i was a little busy
Glad we could help
Apresto
0
 
amazingwolf1Commented:
Thank you, aspresto - hope we will ALL stay as busy as we can :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now