|
sortkey()
The
string function
sortkey()
generates a
value,
which determines the sort order for query results.
Using this function the default binary sort order can be avoided. The return value of
the string function sortkey() is always of
datatype
varbinary.
Syntax of the String Function sortkey()
sortkey ( char_expression | uchar_expression)
[, {"collation_name" | collation_id}] )
The parameters of the String Function sortkey()
"char_expression"
The
parameter
"char_expression" can be a
variable
or
constant
and must be of one of the
datatypes
char,
varchar,
nchar
or
nvarchar.
"uchar_expression"
The parameter "uchar_expression" can be a variable or constant and must be of one of the
datatypes
unichar
or
univarchar.
"collation_name" und "collation_id"
The parameter "collation_name" must be a valid name for a sort order (collating name), set in
single or double quotes. On this topic, see table "collation names and ids" below. Alternatively, the
"collation_id" can be specified.
If the parameter "collation_name" or "collation_id" is not specified,
the function sortkey() automatically uses binary sort order.
| collation names and ids |
| Description |
collation_name |
collation_id |
| Standard Unicode Multilingual |
default |
20 |
| Thai Dictionary Sort Order |
thaidict |
21 |
| ISO14651 Standard |
iso14651 |
22 |
| UTF-16 Sort Order – Equivalent to UTF-8 Binary Sort Order |
utf8bin |
24 |
| CP 850 Alternative – "no accent" |
altnoacc |
39 |
| CP 850 Alternative – lower case letters first |
altdict |
45 |
| CP 850 Western European – Ignoring Upper And Lower Case |
altnocsp |
46 |
| CP 850 Scandinavian Dictionary Sort Order |
scandict |
47 |
| CP 850 Scandinavian – "case-insensitive" |
scannocp |
48 |
| GB Pinyin |
gbpinyin |
n/a |
| Binary Sort Order |
binary |
50 |
| Latin-1 English, French, German Dictionary Sort Order |
dict |
51 |
| Latin-1 Englishe, French, German "no case" |
nocase |
52 |
| Latin-1 English, French, German "no case", "preference" |
nocasep |
53 |
| Latin-1 English, French, German "no accent" |
noaccent |
54 |
| Latin-1 Spanish Dictionary |
espdict |
55 |
| Latin-1 Spanish "no case" |
espnocs |
56 |
| Latin-1 Spanish "no accent" |
espnoac |
57 |
| ISO 8859-5 Russian Dictionary |
rusdict |
58 |
| ISO 8859-5 Russian "no case" |
rusnocs |
59 |
| ISO 8859-5 Cyrillic Dictionary |
cyrdict |
63 |
| ISO 8859-5 Cyrillic "no case" |
cyrnocs |
64 |
| ISO 8859-7 Greek Dictionary |
elldict |
65 |
| ISO 8859-2 Hungarian Dictionary |
hundict |
69 |
| ISO 8859-2 Hungarian "no accents" |
hunnoac |
70 |
| ISO 8859-2 Hungarian "no case" |
hunnocs |
71 |
| ISO 8859-9 Turkish Dictionary |
turdict |
72 |
| ISO 8859-9 Turkish "no accents" |
turknoac |
73 |
| ISO 8859-9 Turkish "no case" |
turknocs |
74 |
| CP932 Binary Sort Order |
cp932bin |
129 |
| Chinese Phonetic Sort Order |
dynix |
130 |
| GB2312 Binary Sort Order |
gb2312bn |
137 |
| Common Cyrillic Dictionary |
cyrdict |
140 |
| Turkish Dictionary |
turdict |
155 |
| EUCKSC Binary Sort Order |
euckscbn |
161 |
| Chinese Phonetic Sort Order |
gbpinyin |
163 |
| Russian Dictionary Sort Order |
rusdict |
165 |
| SJIS Binary Sort Order |
sjisbin |
179 |
| EUCJIS Binary Sort Order |
eucjisbn |
192 |
| BIG5 Binary Sort Order |
big5bin |
194 |
| Shift-JIS Binary Sort Order |
sjisbin |
259 |
Example for the String Function sortkey()
select * from table_name
where column_name
like "%search_string%"
order by sortkey(column_name, "dict")
Sorts the result from table "table_name" according to
"Latin-1 English-French-German Dictionary Sort Order".
See also:
ASE T-SQL - Aggregate Functions, ascii(), char(), char(n), charindex(), char_length(), compare(), difference(), lower(), ltrim(), patindex(), replicate(), reverse(), right(), rtrim(), soundex(), space(), str(), String Functions, stuff(), substring(), to_unichar(), uhighsurr(), ulowsurr(), upper(), uscalar().
|