By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,413 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,413 IT Pros & Developers. It's quick & easy.

when I insert table, value is a string contains apostrophe - it throws an error there

P: 365
When I do INSERT like below, value is a string with apastrophe (for ex: "Checking for 'hlt' instruction"), insert throws an error - how to fix?

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Feb 3 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 2,878
Remove those quotes. If you need, replace it with something else. Then replace it back when you're retrieving it.

Happy Coding!!!

~~ CK
Feb 3 '10 #2

P: 2
This should only be an issue if you're using string literals in a script, in which case you can double the single quotes in the string, e.g.:
Expand|Select|Wrap|Line Numbers
  1. INSERT dbo.table_name(column1)
  2. VALUES('Checking for ''hit'' instruction');
Based on your using double quotes around the value and calling its data type a "string," I infer that this value is coming from your front-end programming language, in which case you should use parameterized commands, be they text or stored procedures, as that will both obviate such issues and guard against SQL injection attacks.
Feb 6 '10 #3

P: 365
Thanks, actually this is using lua script, I found an escape sequence to do that, I fixed this. thanks.
Feb 6 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.