0

Hi techies, I have searched so many "Replace" function topics, but there is something that I don't understand....I found some like this... Replace(strField, " ' ", " ' ' ") .... do anyone knows what's the use of replaceing ' with ' ' ? Tnx in advance.

2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by samaru
0

That's to escape apostrophe signs usually in query strings. If you have a query string, let's say something like this:

name = "Lori"
sql = "select * from customers where name = ' " & name & " ' "

There won't be a problem. The sql statement, after it's been merged with the variable name will look like this:

select * from customers where name = ' Lori '

Which is a perfectly legit SQL statement. BUT if you had something like this:

name = "O'Neil"
sql = "select * from customers where name = ' " & name & " ' "

It would crap out because of that apostrophe sign in O'Neil. So the SQL statement will look like this:

select * from customers where name = ' O'Neil '

Which the database will think the apostrophe after the O is the end of the SQL statement and will wonder about the trailing "Neil" - how do you fix this? You escape the apostrophe sign by double it. So it would look like this:

select * from customers where name = ' O''Neil '

And that's why that replace function replaces single apostrophes with doubles.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.