No of visitors who read this post: 495
Category: MS SQL Server
Type: Question
Author: Grahamamie
No votes yet

 Hi all,

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

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

# (Solution Accepted)

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.

# (Solution Accepted)

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

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

#

Thank you both for the help.