Why is sql server storing question mark characters instead of Japanese characters in NVarchar fields?

前端 未结 8 1499
春和景丽
春和景丽 2020-12-01 12:18

I\'m trying to store Japanese characters in nvarchar fields in my SQL Server 2000 database.

When I run an update statement like:

update blah 
set add         


        
相关标签:
8条回答
  • 2020-12-01 12:20

    you need to write N before the string value. e.g.INSERT INTO LabelManagement (KeyValue) VALUES (N'変更命令'); Here I am storing value in japanese language and i have added N before the string character. I am using Sql server 2014. Hope you find the solution. Enjoy.

    0 讨论(0)
  • 2020-12-01 12:21

    This cannot be a correct answer given your example, but the most common reason I've seen is that string literals do not need a unicode N prefix.

    So, instead of

    set address = N'スタンダードチャ'
    

    one would try to write to a nvarchar field without the unicode prefix

    set address = 'スタンダードチャ'
    

    See also: N prefix before string in Transact-SQL query

    0 讨论(0)
  • 2020-12-01 12:28

    I was facing this same issue when using Indian languages characters while storing in DB nvarchar fields. Then i went through this microsoft article -

    http://support.microsoft.com/kb/239530

    I followed this and my unicode issue got resolved.In this article they say - You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server

    SQL Server Unicode Support

    SQL Server Unicode data types support UCS-2 encoding. Unicode data types store character data using two bytes for each character rather than one byte. There are 65,536 different bit patterns in two bytes, so Unicode can use one standard set of bit patterns to encode each character in all languages, including languages such as Chinese that have large numbers of characters.

    In SQL Server, data types that support Unicode data are:

    nchar
    nvarchar
    nvarchar(max) – new in SQL Server 2005
    ntext
    

    Use of nchar, nvarchar, nvarchar(max), and ntext is the same as char, varchar, varchar(max), and text, respectively, except:

    - Unicode supports a wider range of characters.
    - More space is needed to store Unicode characters.
    - The maximum size of nchar and nvarchar columns is 4,000 characters, not 8,000     characters like char and varchar.
    - Unicode constants are specified with a leading N, for example, N'A Unicode string'
    

    APPLIES TO

    Microsoft SQL Server 7.0 Standard Edition
    Microsoft SQL Server 2000 Standard Edition
    Microsoft SQL Server 2005 Standard Edition
    Microsoft SQL Server 2005 Express Edition
    Microsoft SQL Server 2005 Developer Edition
    Microsoft SQL Server 2005 Enterprise Edition
    Microsoft SQL Server 2005 Workgroup Edition
    
    0 讨论(0)
  • 2020-12-01 12:32

    SSMS will not display that correctly, you might see question marks or boxes

    paste the results into word and they should be in Japanese

    In the webpage you need to set the Content-Type, the code below will display Chinese Big5

    <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=big5"> 
    

    To verify the data you can't use ascii since ascii only can see the ascii character set

    run this

    select unicode(address),ascii(address) from blah where key_ID = 1

    Output should be the following (it only looks at the first character) 12473 63

    0 讨论(0)
  • 2020-12-01 12:34

    You need to check the globalisation settings of all the code that deals with this data, from your database, data access and presentation layers. This includes SSMS.

    (You also need to work out which version you are using, 2003 doesn't exist...)

    0 讨论(0)
  • 2020-12-01 12:40

    We are using Microsoft SQL Server 2008 R2(SP3). Our table collation is specified as SQL_Latin1_General_CP1_CI_AS. I have my types specified as the n variety

    nvarchar(MAX)
    nchar(2)
    

    ..etc

    To insert Japanese characters I prefix the string with a capital N

    N'素晴らしい一日を'
    

    Works like a charm.

    0 讨论(0)
提交回复
热议问题