sql server 按拼音分类排序的功能

  A   阿杜       阿牛       阿翔         
  B   Bjack         
  C   陈小春       成龙       陈百强       陈冠蒲       陈冠希       陈浩民       陈庆祥       陈升       陈司翰       陈晓东      
陈奕迅       陈明章       
  D   杜德伟       迪克牛仔       邓建明       邓健泓         
  E     
  F   范逸臣       方力申       费玉清       房祖名       范宗沛         
  G   恭硕良       古巨基       古天乐       光良       郭富城       郭品超       郭伟亮         
  H   黄品源       黄贯中       黄国俊       黄维得       黄耀明       黄义达       黄立行       黄家强         
  I     
  J   姜育恒         
  K   孔令奇         
  L   刘德华       罗文       李克勤       李圣杰       李宗盛       梁朝伟       梁汉文       林海峰       林俊杰       林佑威       
林志炫       林志颖       林子良       林子祥       
  M   马俊伟

 

Java代码   收藏代码
  1. create function fun_getPY(@str nvarchar(4000))  
  2. returns nvarchar(4000)  
  3. as  
  4. begin  
  5. declare @word nchar(1),@PY nvarchar(4000)  
  6. set @PY=''  
  7. while len(@str)>0  
  8. begin  
  9. set @word=left(@str,1)  
  10. --如果非汉字字符,返回原字符  
  11. set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901  
  12. then (select top 1 PY from (  
  13. select 'A' as PY,N'驁' as word  
  14. union all select 'B',N'簿'  
  15. union all select 'C',N'錯'  
  16. union all select 'D',N'鵽'  
  17. union all select 'E',N'樲'  
  18. union all select 'F',N'鰒'  
  19. union all select 'G',N'腂'  
  20. union all select 'H',N'夻'  
  21. union all select 'J',N'攈'  
  22. union all select 'K',N'穒'  
  23. union all select 'L',N'鱳'  
  24. union all select 'M',N'旀'  
  25. union all select 'N',N'桛'  
  26. union all select 'O',N'漚'  
  27. union all select 'P',N'曝'  
  28. union all select 'Q',N'囕'  
  29. union all select 'R',N'鶸'  
  30. union all select 'S',N'蜶'  
  31. union all select 'T',N'籜'  
  32. union all select 'W',N'鶩'  
  33. union all select 'X',N'鑂'  
  34. union all select 'Y',N'韻'  
  35. union all select 'Z',N'咗'  
  36. ) T  
  37. where word>=@word collate Chinese_PRC_CS_AS_KS_WS  
  38. order by PY ASC) else @word end)  
  39. set @str=right(@str,len(@str)-1)  
  40. end  
  41. return @PY  
  42. end  

查询语句:

--函数调用实例: 
--select dbo.fun_getPY('中华人民共和国')
得到所有A开头的.
select id_,dbo.fun_getPY(tit) from tab where dbo.fun_getPY(tit) like 'A%' order by dbo.fun_getPY(tit)
B开头的类似:
select id_,dbo.fun_getPY(tit) from tab where dbo.fun_getPY(tit) like 'B%' order by dbo.fun_getPY(tit)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值