Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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

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 tim.');

1 Answer

0 votes
by (40.7k points)

If you are using SQL Server 2008, then following query will work well in your case:

DECLARE @My_Table TABLE (

    [value] VARCHAR(200)

)

INSERT INTO @My_Table VALUES ('Hi, My name''s Tim.')

SELECT * FROM @My_Table

Output:

Hi, My name's Tim.

You can escape the single quote by doubling them up.

Related questions

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer
0 votes
3 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...