Not able to insert the text in SQL query which has apostrophe

Asked By 20 points N/A Posted on -
qa-featured

Hi all,

Please provide me a solution to insert the text which has apostrophe. Example : aaab's.

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'GH'.

Messages:

Msg 102, Level 15, State 1, Line 1

Incorrect syntax near 'GH'.

Msg 105, Level 15, State 1, Line 1

Unclosed quotation mark after the character string ')

'.

Thanks in advance.

Grahamamie

SHARE
Best Answer by deshow06
Answered By 0 points N/A #93198

Not able to insert the text in SQL query which has apostrophe

qa-featured

Yes, that is a problem many users of SQL face. Using an apostrophe in the code, requires a small and easy task. It needs to be done just as in the HTML code, which you code. You should replace each apostrophe with two, so that you can insert an apostrophe into the code.

For example if you want to insert an apostrophe into the code try the following:

Insert into foo (name) values ('duncan o''toole")

Cheers.

Best Answer
Best Answer
Answered By 0 points N/A #93199

Not able to insert the text in SQL query which has apostrophe

qa-featured
  • In SQL strings are enclosed within single quotes '………' . So if a string has an apostrophe within it, then it has to result in an error.
  • The solutions is to put two apostrophes in the string, as show below:
enclosed within single quotes

Or Using most of the programming language by replacing the single quotes with a double quote by use of replace function. For example in vb.net as shown below:

double quote by use of replace function
Answered By 20 points N/A #93200

Not able to insert the text in SQL query which has apostrophe

qa-featured

Thank you both for the help.

Related Questions