inserting single quotes

J

Jesper F

How can I insert text into a table when the text contains single quotes
within the SQL-statement?
I get an error when trying:
INSERT INTO tablename (field1,field2) VALUES ('testtext','Y'all')
What's the workaround for this?
Thanks.
 
K

Ken Snell [MVP]

You need to double up the single quotes in the string. You can do this by
using the Replace function. Check it out in Help and post back if you have
questions.
 
J

John Vinson

How can I insert text into a table when the text contains single quotes
within the SQL-statement?
I get an error when trying:
INSERT INTO tablename (field1,field2) VALUES ('testtext','Y'all')
What's the workaround for this?
Thanks.

Double up the apostrophes, or delimit the strings with " instead of ':

INSERT INTO tablename (field1, field2) VALUES ('testtext', 'Y''all')

or

INSERT INTO tablename (field1, field2) VALUES ("testtext", "Y'all")

The " delimiter works in Access JET syntax, but not (I believe) in
SQL/Server's dialect.

John W. Vinson[MVP]
 
J

Jesper F

Double up the apostrophes, or delimit the strings with " instead of ':

Thanks a lot to both of you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top