8

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.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Sabri Aziri
  • 3,834
  • 5
  • 27
  • 45

2 Answers2

25

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?

Community
  • 1
  • 1
Nenad Zivkovic
  • 17,090
  • 6
  • 41
  • 53
0

I'm not sure if you are doing a static stored procedure or scripting, but maybe the text is not being encoded properly when you save it to disk. I ran into this, and my problem was solved in PowerShell by correcting the encoding of the SQL that I saved to disk for osql processing:

     Out-File -FilePath "MyFile.sql" -InputObject $MyRussianSQL -Encoding "Unicode" -Force;
     & osql -U myuser -P password -i "MyFile.sql";
CZahrobsky
  • 695
  • 7
  • 7