Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cyrillic symbols in SQL code are not correctly after insert

I use SQL Server 2005 and I am try to store Cyrillic characters but I can't with SQL code by trying to run this is SQL Server:

INSERT INTO Assembly VALUES('Македонски парлиамент број 1','','');

Or from C# is happening the same problem but inserting/updating the column from SQL Server it work and it is store normally.

The datatype of column is nvarchar.

like image 586
Sabri Aziri Avatar asked May 26 '13 17:05

Sabri Aziri


People also ask

How do you handle special characters in SQL?

How do you handle special characters in SQL query? Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence.


1 Answers

You have to add N prefix before your string.

When you implicitly declare a string variable it is treated as varchar by default. Adding prefix N denotes that the subsequent string is in Unicode (nvarchar).

 INSERT INTO Assembly VALUES(N'Македонски парлиамент број 1','','');

Here is some reading:

http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an-n-prefix.html

https://msdn.microsoft.com/en-IN/library/ms186939.aspx

What is the meaning of the prefix N in T-SQL statements?

like image 199
Nenad Zivkovic Avatar answered Oct 02 '22 11:10

Nenad Zivkovic