Unicode normalization in SQL Server 2008 R2

@ I have a row in a table that contains the following text "Urbański, Mariusz". The hexagonal representation for the symbol "ń" is "6e cc 81". Thus, it is saved in the form of Unicode decomposition.

When I use a query such as "...... where Identification = N'Urbański, Mariusz" and the symbol "ń" corresponds to the decomposition form ("6e cc 81"), the query returns the expected records.

If I run the same query using the Unicode form normalization form ("ń" = "c5 84"), I get no results.

I also tried "Choose 1, where N'Urbański, Mariusz = N'Urbański, Mariusz", where I use 2 variations of "ń", which are always true.

Is there a way to force SQL Server to consider 2 values ​​equal?

Here my database configuration is requested by Rhys Jones

Database Collation : "Danish_Norwegian_CI_AS"
Column1 : IdRightsHolderSourceIdentification = NULL  
Column2 : VersionInfo = NULL  
Column3 : Source = "Danish_Norwegian_CI_AS"
Column4 : Identification = "SQL_Latin1_General_CP437_BIN"
Column5 : RightsHolder = NULL

The problem column, as Rhys Jones, column4 guesses very well, has binary sorting (what does the BIN at the end mean?). Thank you very much for your help.

+4
source share
1 answer

, Unicode, , , , , SQL Server - . , SQL Server . script, . SQL Server, , Latin1_General_CI_AS, ARE . , , . ( ) .

, ,

-- UTF8 character list -- http://www.fileformat.info/info/charset/UTF-8/list.htm?
--    n - LATIN SMALL LETTER N (U+006E) 6e 
--    ́    - COMBINING ACUTE ACCENT (U+0301) cc81 
--    ń - LATIN SMALL LETTER N WITH ACUTE (U+0144) c584 

create table dbo.MyTable (id int not null, name nvarchar(100) collate Latin1_General_CI_AS not null)

declare @a nvarchar(100); set @a = N'Urba' + nchar(0x0144) + N'ski, Mariusz'
declare @b nvarchar(100); set @b = N'Urba' + nchar(0x6e) + nchar(0x0301) + N'ski, Mariusz'

insert dbo.MyTable values (1, @a)
insert dbo.MyTable values (2, @b)

-- Display server, database and column collations
select
    SERVERPROPERTY(N'Collation') as [server_collation],
    DATABASEPROPERTYEX(DB_NAME(), N'Collation') as [database_default_collation],
    c.collation_name as [column_collation]
from
    sys.objects t join sys.columns c on c.object_id = t.object_id
where 
    t.object_id = object_id('dbo.MyTable') and c.name = 'name'

-- Test with Latin1_General_CI_AS
select id, name from dbo.MyTable where name collate Latin1_General_CI_AS = @a collate Latin1_General_CI_AS

-- Test with French_CI_AS
select id, name from dbo.MyTable where name collate French_CI_AS = @a collate French_CI_AS

-- Test with Latin1_General_BIN2
select id, name from dbo.MyTable where name collate Latin1_General_BIN2 = @a collate Latin1_General_BIN2
+2

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


All Articles