USE [tempdb];
-- DROP TABLE dbo.OddSort;
CREATE TABLE dbo.OddSort
(
id INT IDENTITY(1,1) PRIMARY KEY,
col1 NVARCHAR(5) COLLATE Latin1_General_100_CS_AS,
col2 NVARCHAR(5) COLLATE Latin1_General_100_CS_AS,
col3 NVARCHAR(5) COLLATE Latin1_General_100_CS_AS
);
GO
INSERT dbo.OddSort (col1, col2, col3)
VALUES (N'e', N'eA', N'èN'e 1'A')
, (N'ê', N'êE', N'ê 5'E')
, (N'é', N'éH', N'aN'é 9'H')
, (N'ë', N'ëC', N'eN'ë 2'C')
, (N'E', N'EG', N'E 7'G')
, (N'Ë', N'ëh', N'ËN'ë 0'h')
, (N'è', N'èD', N'éN'è 4'D')
, (N'é', N'éB', N'ēN'é 3'B')
, (N'ë', N'ëH', N'eN'ë 8'H')
, (N'ē', N'ēF', N'ëN'ē 6'F');
id col3
31 ae 9A
68 Ëé 0B
14 èë 1C
47 eè 2D
82 ēê 3E
7 10 éē 4F
25 êE 5G
103 ë 6é H
56 Eë 7h
9 eë 8H
What we can see in the results above:
- The sort order is exactly the same as in Test 2. The only difference in the test values here is that there is a space between each character, removing the possibility of contextual rules. Hence, we know that the reason for the difference in sort order for
col2
in the question is again due to "Multi-Level Comparison", and not "Contextual Sensitivity".
- Since the datatype is
NVARCHAR
, we are only concerned with Unicode Code Points and sorting algorithms, hence the use of theUNICODE()
function in TEST 1. While Code Pages are specified by most Collations, they only pertain toVARCHAR
data. Meaning, while Code Page 1252 is specified by theLatin1_General*
series of Collations, that can be ignored here.Since the datatype is
NVARCHAR
, we are only concerned with Unicode Code Points and sorting algorithms, hence the use of theUNICODE()
function in TEST 1. While Code Pages are specified by most Collations, they only pertain toVARCHAR
data. Meaning, while Code Page 1252 is specified by theLatin1_General*
series of Collations, that can be ignored here. The weights described in the Default Unicode Collation Element Table (DUCET) (Version 5.0.0 which should map to the
_100_
series Collations) are fine for US English, but not other locales / languages. Other languages need to start with the DUCET and then apply locale-specific override rules as defined by the Common Locale Data Repository (CLDR) project. From what I can tell, versions 1.4 / 1.4.1 were released in 2006. To get those overrides, download the CLDR 1.4 "core" file via http://unicode.org/Public/cldr/1.4.0/core.zip, then, in that zip file, go to the collation folder and find the XML file corresponding to the locale being used. Those files contain just the overrides, and are not complete sets of collation rules.