SQL Server排序規(guī)則的應(yīng)用
SQL Server排序規(guī)則在SQL數(shù)據(jù)庫(kù)中都有哪些應(yīng)用呢?下面就為您介紹SQL Server排序規(guī)則的應(yīng)用方面的知識(shí),如果您感興趣的話,不妨一看。
SQL Server排序規(guī)則的應(yīng)用:
sql server提供了大量的windows和sqlserver專用的排序規(guī)則,但它的應(yīng)用往往被開(kāi)發(fā)人員所忽略。其實(shí)它在實(shí)踐中大有用處。
例1:讓表name列的內(nèi)容按拼音排序:
- create table #t(id int,name varchar(20))
- insert #t select 1,中
- union all select 2,國(guó)
- union all select 3,人
- union all select 4,阿
- select * from #t order by name collate chinese_prc_cs_as_ks_ws
- drop table #t
/*結(jié)果:
- id name
- ----------- --------------------
- 4 阿
- 2 國(guó)
- 3 人
- 1 中
- */
例2:讓表name列的內(nèi)容按姓氏筆劃排序:
- create table #t(id int,name varchar(20))
- insert #t select 1,三
- union all select 2,乙
- union all select 3,二
- union all select 4,一
- union all select 5,十
- select * from #t order by name collate chinese_prc_stroke_cs_as_ks_ws
- drop table #t
/*結(jié)果:
- id name
- ----------- --------------------
- 4 一
- 2 乙
- 3 二
- 5 十
- 1 三
- */
【編輯推薦】


















