0 votes
1 view
in SQL by (22.4k 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.3k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...