Back
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.');
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
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.
31k questions
32.8k answers
501 comments
693 users