How to Escape a Single Quote in SQL Server? – Interview Question of the Week #192

Question: How to Escape a Single Quote in SQL Server?

Answer: Yesterday, I had an opportunity to visit a SQL User Group in Bangalore, India, and during the event, I had received a very simple question from a college student. As soon as he asked the question, everyone laughed at this question as the question was relatively simple if you are a SQL Server professional.

How to Escape a Single Quote in SQL Server? - Interview Question of the Week #192 escapesinglequote

At one point in time, we were all beginners and we all struggled with the simple questions too. I really felt bad when everyone laughed at the newbie. I decided to answer him during the session and here is the simple possible way to escape a single quote in SQL Server string.

You can escape a single quote with another single quote. Here is the example –

How to Escape a Single Quote in SQL Server? - Interview Question of the Week #192 selectescape

Please note that you can’t escape with a double quote but with double single quotes.

Here are few of the previous blog posts related to Interview Questions and Answers:

Reference: Pinal Dave (http://blog.SQLAuthority.com)

, ,
Previous Post
Where is the Default Settings for Backup Compression? – Interview Question of the Week #191
Next Post
How to STOP the Usage of SELECT * For Views? – Interview Question of the Week #193

Related Posts

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

    Reply

Leave a Reply

Menu