Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quotation 1

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
I've done some inserts/updates inserting variables into SQL statements e.g:

"UPDATE table SET attribute = '" & variable & "'"

problem is, if the user puts in a value into variable e.g:

he'llo ... or ... chris's

Then the execution messes up, as SQL thinks that the apostrophes are part of the statement.

How can I get SQL to take any apostrophe's inside the two in the statement '" "' as just part of the value?

(would a good approach be - if a ' is detected double it?)

Chris.


 
That's exactly what you want to do. The easiest way is to use the VBScript Replace() function, as in:
Code:
"UPDATE table SET attribute = '" & Replace(variable, "'", "''") & "'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top