HNIM600
HNIM600

Reputation: 37

SQL Server error with ' ' insert into table

INSERT INTO Article (CatID, Title, Content) 
VALUES ('100', 'New color, new choice', '<span style="font-family:'Times New Roman'">etc...etc</span>')

I try to insert data into a table in SQL Server with this command, but I get an error:

Incorrect syntax near 'Times'

What is wrong here, and how can I fix it?

Upvotes: 0

Views: 729

Answers (3)

Arulkumar
Arulkumar

Reputation: 13237

Around the Times New Roman in the Content value, you need to add ' to escape the single quotes:

INSERT INTO Article (
    CatID
    ,Title
    ,Content
    )
VALUES (
    '100'
    ,'New color, new choice'
    ,'<span style="font-family:''Times New Roman''">etc...etc</span>'
    )

Upvotes: 1

DavidG
DavidG

Reputation: 118947

You have unescaped single quotes in the third column. Use a double single quote ('') to escape that:

INSERT INTO Article
(CatID, Title, Content) 
VALUES
('100', 'New color, new choice', '<span style="font-family:''Times New Roman''">etc...etc</span>')
                                                     --    ^^ This and this ^^

Upvotes: 1

Roberto
Roberto

Reputation: 2185

You need to escape single quote, using two single quotes:

Insert into Article(CatID, Title, Content) values ('100','New color, new 
choice','<span style="font-family:''Times New Roman''">etc...etc</span>')

Right after and before Times New Roman there are two ' characters instead of one, otherwise the interpreter will think the string ends with ...family:

Upvotes: 1

Related Questions