Cyrillic characters in SQL code is not correct after insertion

I am using SQL Server 2005 and I am trying to store Cyrillic characters, but I can not with SQL code trying to run this SQL Server:

INSERT INTO Assembly VALUES('  ј 1','',''); 

Or from C # the same problem happens, but inserting / updating a column with SQL Server works, and that’s fine.

nvarchar column data type.

+4
source share
2 answers

You need to add the prefix N in front of your line.

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

  INSERT INTO Assembly VALUES(N'  ј 1','',''); 

Here are some examples:

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 N prefix in T-SQL statements?

+14
source

I'm not sure if you are executing a static stored procedure or scripts, but maybe the text is not correctly encoded when saving to disk. I ran into this and my problem was resolved in PowerShell by correcting the SQL encoding that I saved on disk for osql processing:

  Out-File -FilePath "MyFile.sql" -InputObject $MyRussianSQL -Encoding "Unicode" -Force; & osql -U myuser -P password -i "MyFile.sql"; 
0
source

Source: https://habr.com/ru/post/1482841/


All Articles