sql server 2012 express do not understand Russian letters

后端 未结 2 471
梦毁少年i
梦毁少年i 2021-01-05 02:41

I have DB which is working with Russian text however when i run queries it shows me this. Database will used by Russians and it has to show Russian text properly!

2条回答
  •  有刺的猬
    2021-01-05 03:03

    Are you sure the data has been stored in the database correctly? How do you know?

    Make sure that the column has a proper collation, that it is defined as nvarchar and that inserts of string literals are prefixed with N. For example, these are not the same:

    INSERT dbo.table(column) SELECT 'foo';
    INSERT dbo.table(column) SELECT N'foo';
    

    As an example:

    USE tempdb;
    GO
    
    CREATE TABLE dbo.foo
    (
      ID INT PRIMARY KEY,
      bar NVARCHAR(32) COLLATE SQL_Ukrainian_CP1251_CI_AS
    );
    
    INSERT dbo.foo SELECT 1,'АБВГДЕЖЅZЗИІКЛ';
    INSERT dbo.foo SELECT 2,N'АБВГДЕЖЅZЗИІКЛ';
    
    SELECT ID, bar FROM dbo.foo;
    GO
    DROP TABLE dbo.foo;
    

    Results:

    ID    bar
    ----  --------------
    1     ????????Z?????
    2     АБВГДЕЖЅZЗИІКЛ
    

    And to show how this affects your insert statement, your string is missing the N prefix:

    SELECT
      CONVERT(NVARCHAR(32), 'Иванов'),
      CONVERT(NVARCHAR(32), N'Иванов');
    

    Results:

    ------    ------
    ??????    Иванов
    

    So, prefix your Unicode strings with N'a prefix' or lose data.

提交回复
热议问题