How do I escape a single quote in SQL Server

0 votes
I'm trying to insert some text data into a table in SQL Server.

The text includes a single quote(').

How do I escape that?

I tried using two single quotes, but it threw me some errors.

eg. insert into my_table values('hi, my name''s edureka.');
Jul 21, 2020 in PHP by kartik
• 37,510 points
5,843 views

1 answer to this question.

0 votes

Hello @kartik,

Single quotes are escaped by doubling them up, just as you've shown us in your example. The following SQL illustrates this functionality. I tested it on SQL Server:

DECLARE @my_table TABLE (
    [value] VARCHAR(200)
)

INSERT INTO @my_table VALUES ('hi, my name''s edureka.')

SELECT * FROM @my_table

Results

value
hi, my name's edureka.

Hope it helps!!
ThanK you!!

answered Jul 21, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
1 answer

How can I do an UPDATE statement with JOIN in SQL Server?

Hello @kartik, This should work in SQL Server: update ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,880 points
610 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
9,440 views
0 votes
1 answer

How to Insert multiple rows in a single SQL query?

Hello @kartik, In SQL Server you can insert ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,880 points
4,156 views
0 votes
1 answer

How Do I Get the Query Builder to Output Its Raw SQL Query as a String?

Hello @kartik, Use the toSql() method on a QueryBuilder instance. DB::table('users')->toSql() would return: select * ...READ MORE

answered Jul 22, 2020 in PHP by Niroj
• 82,880 points
811 views
0 votes
1 answer

How to access PHP var from external javascript file?

Hello @kartik, You don't really access it, you ...READ MORE

answered Jul 6, 2020 in Java-Script by Niroj
• 82,880 points
7,113 views
0 votes
1 answer

How to specify a port to run a create-react-app based project?

Hello @kartik, You could use cross-env to set the port, ...READ MORE

answered Jul 22, 2020 in Angular by Niroj
• 82,880 points
5,273 views
0 votes
1 answer

How do you set a default value for a MySQL Datetime column?

Hello @kartik, In version 5.6.5, it is possible ...READ MORE

answered Aug 18, 2020 in PHP by Niroj
• 82,880 points
7,342 views
0 votes
1 answer

How to move columns in a MySQL table?

Hello @kartik, If empName is a VARCHAR(50) column: ALTER ...READ MORE

answered Aug 19, 2020 in PHP by Niroj
• 82,880 points
2,312 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

Hello @kartik, In SQL Server, use MERGE MERGE INTO YourTable ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,880 points
680 views
0 votes
1 answer

How to concatenate text from multiple rows into a single text string in SQL server?

Hello @kartik, Use COALESCE: DECLARE @Names VARCHAR(8000) SELECT @Names = ...READ MORE

answered Jul 21, 2020 in PHP by Niroj
• 82,880 points
2,754 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP