0

I have a table in my SQL Server database with a column of type nvarchar(50);

I tried to do this:

  1. Right click on my table

  2. Selecting "Edit 200 first rows"

  3. Typing in that column 'a'

I get an error like this:

Error source: .Net SqlClient Data Provider.
Error message: Incorrect syntax near 'a'.
Correct the errors and retry".

Why do I get this error message and how can I fix this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tal Malaki
  • 422
  • 5
  • 18
  • There is NO circumstance in which you should be adding or changing records this way. If you need changes to data they should alawys be done thorough sql scripts. – HLGEM Nov 26 '13 at 14:07

2 Answers2

2

I have used aqua data studio and tested this it is allowing me.

my result:::

 id     testc     
 -----  --------- 
 1      'asdfasd'

If you want to use it thrugh .net then while passing the string add the escape sequences. suppose if you are sending "'"--single quote.. then send I have used and tested this it like "\'" is allowing me.

refer below link:::

http://www.codeproject.com/Questions/157918/How-can-I-insert-a-special-character-in-sql-server

dev
  • 715
  • 5
  • 21
0

I have had the same error.
I want to insert a value I am Nam 'ABC' into MyTable at field Description as following SQL statement

Insert Into table MyTable (Description) values('I am Nam 'ABC'');

Once Insert command executed the error occur immediately

Incorrect syntax near 'ABC'.

Note that the reason why is SQL will understand character " ' " which before ABC belongs to character " ' " before I, and one after ABC belongs to " ' " at the end. As a result ABC does not belong to SQL statement anymore therefore it makes a break of statement.

Here is my solution:
I added two single quotes for each side of ABC

Insert Into table MyTable (Description) values('I am Nam ' 'ABC' ' ');
Pang
  • 9,564
  • 146
  • 81
  • 122
Nam_Unity
  • 1
  • 1