single quotes imbedded in sql string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to format an sql query (to avoid errors) when a single
quote is imbedded in a parameter e.g.
select field2 where field1 IN ('abc', 'd'fg','hij').
The ' in d'fg cause an error, but the database field actually contains the
'. Sometimes this is found where feet are abreviated to '
thank you in advance.
 
NJS said:
Does anyone know how to format an sql query (to avoid errors) when a single
quote is imbedded in a parameter e.g.
select field2 where field1 IN ('abc', 'd'fg','hij').
The ' in d'fg cause an error, but the database field actually contains the
'. Sometimes this is found where feet are abreviated to '
thank you in advance.

Double the quotes. E.g. (Access 2000 & greater):

str = "d'fg"
str = Replace(str, "'", "''")
' str now equals "d''fg"
 
Back
Top