How to escape single quote in SQL Server?

 Posted by vishalneeraj-24503 on 12/1/2014 | Category: Sql Server Interview questions | Views: 359 | Points: 40
Answer:

Suppose,we have a Test's value,which we have to insert on one column in a table,so if we write
INSERT INTO TEST1(NAME,ADDRESS) VALUES('TEST'S','ABC'D');

Then it will give error as
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'S'.


To overcome above problem,
We can escape the single quotes by doubling or inserting two single quotes as shown in the below query as
INSERT INTO TEST1(NAME,ADDRESS) VALUES('TEST''S','ABC''D');
.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response