Reputation: 149
I'm trying to insert data into my Azure database, but I keep getting this error:
Failed to execute query. Error: Unclosed quotation mark after the character string '
you'.
Incorrect syntax near '
you'.
The only code I'm trying to insert into the database is as follows:
SET IDENTITY_INSERT [dbo].[Articles] ON
GO
INSERT [dbo].[Articles] ([Id], [Title], [Description], [Thumbnail], [VideoLink], [Developer], [Publisher], [ReleaseDate], [PublishDate], [ReviewConsole], [Text], [Score]) VALUES (2, N'Donkey Kong 64', N'My mighty review of the Guinness World Record-setting Donkey Kong 64.', N'DK64.png', N'eXlRymN6uxM', N'Rare', N'Nintendo', N'11/22/1999', N'2/15/2016', N'N64', N'
you go ', 7)
GO
What's strange is that if I put the "you go" data on the second line it works just fine, but this would be incredibly tedious to perform for every single line since I have over 2500 to move. Is there a reason for this error and if so, is there a simple way to get rid of it?
Upvotes: 1
Views: 2262
Reputation: 17374
Not properly answered so I will answer it here. You are inserting fields which contains text such as "I'd like to go" that is single quote in one form or another. You need to escape these. You can use string replace function so "I'd like to go" would be become "I''d like to go" when you insert into to DB. Inside DB, it will go in as "I'd like to go", that is without the double quotation.
Upvotes: 0
Reputation: 2814
The problem is the line break. Interesting it works if its varchar and not nvarchar. But this simple example will fail:
declare @t table (t nvarchar(100))
insert @t values (n'
you go')
select * from @t
While this will work (note its no longer inserted as nvarchar)
declare @t table (t nvarchar(100))
insert @t values ('
you go')
select * from @t
Upvotes: 2