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

John Savill

March 30, 2007

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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?"

Read more about:

Microsoft

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like