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
  • 732,580
  • 175
  • 1,330
  • 1,459
Sabri Aziri
  • 4,084
  • 5
  • 30
  • 45

2 Answers2

27

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
  • 18,221
  • 6
  • 42
  • 55
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
  • 762
  • 7
  • 7