Question: How do you escape a single quote in a SQL Server string?
Answer: Write two single quotes inside the string to represent one single quote in the value.

A college student asked me this at a SQL user group in Bangalore. Some people laughed because it was a simple question for an experienced SQL Server professional. I did not think that was fair. We were all beginners once, and we all struggled with simple questions. Here is the example I used to answer him:
SELECT N'This is SQLAuthority''s author Pinal Dave' AS Message;
A doubled apostrophe becomes one apostrophe. Captured in SSMS on SQL Server 2025.

The result is This is SQLAuthority's author Pinal Dave, with one apostrophe. '' is two single-quote characters, not one double-quote character. SQL Server does not use a backslash to escape an apostrophe in an ordinary T-SQL string literal.
For application input, use parameters rather than constructing a SQL statement by repeatedly escaping user text. That is a different task from writing this literal in a script.
Related interview questions: backup compression defaults, TOP 0 versus a false WHERE, moving database files, SQLDump corruption evidence, and INSERT SELECT versus SELECT INTO.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.





1 Comment. Leave new
Hi Pinal,
I agree with you, even I feel bad. At least, the student wants to clear his doubt and build the core concepts. May be most of the one’s who laughed at him even might not be knowing how to escape single quote. As per my view, it is good to ask even basics questions and make your concepts crystal clear rather than feeling shy of asking.
Thanks,
Srini