当按包含管道字符的字符列排序时,SQL Server 似乎必须做一些特殊的事情。
ascii('|') 和 unicode('|') 一样返回 124
ascii('0') 返回 48
按返回“|”排序 字母和数字前的字符。
我试图查看排序规则,在我查看的情况下,'|' 字符始终具有值 124。
这是我的测试选择
select * from (
select '0' as col1, ASCII('0') as col2, unicode('0') as col3
union select '1' as col1, ASCII('1') as col2, unicode('1') as col3
union select '|' as col1, ASCII('|') as col2, unicode('|') as col3
union select 'a' as col1, ASCII('a') as col2, unicode('a') as col3
union select ' ' as col1, ASCII(' ') as col2, unicode(' ') as col3
union select '.' as col1, ASCII('.') as col2, unicode('.') as col3
union select '/' as col1, ASCII('/') as col2, unicode('/') as col3
) as q
order by col1
此查询返回:
col1 col2 col3
1 32 32
2 . 46 46
3 / 47 47
4 | 124 124
5 0 48 48
6 1 49 49
7 a 97 97
为什么 124 落在 47 和 48 之间?
使用的排序规则是 SQL_Latin1_General_CP1_CI_AI。
如果仅二进制排序规则使用字符的 ascii/unicode 值进行排序,我如何才能找到此排序规则中字符的排序顺序?