How do I insert a single quote (') into a Microsoft SQL Server database?

A. Usually the single quote character is reserved for inserting information into a database, and so if a single quote is contained in the actual data to be inserted, the command often becomes corrupted. To solve the problem, simply replace any single quote with two quotes (not the double quote character but two single-quote characters). The following sample command performs this replacement automatically:

sContent = Replace(sContent,"'","''")

where sContent contains the data that needs single quotes replaced, so that the data can be inserted into a database.

Learn more SQL Server tips from "Creating SQL Server Databases" and "How can I insert the output of a dbcc command into a SQL Server table?"

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.