首先要创建一个存储过程createfunction[dbo].[fn_ChineseToSpell](@strChinesevarchar(500)='')returnsvarchar(500)asbegin/*函数实现开始*/declare@strLenint,@returnvarchar(500),@iintdeclare@nint,@cchar(1),@chnnchar(1)select@strLen=len(@strChinese),@return='',@i=0while@i<@strLenbegin/*while循环开始*/select@i=@i+1,@n=63,@chn=substring(@strChinese,@i,1)if@chn>'z'/*原理:“字符串排序以及ASCII码表”*/select@n=@n+1,@c=casechnwhen@chnthenchar(@n)else@cendfrom(selecttop27*from(selectchn='吖'unionallselect'八'unionallselect'嚓'unionallselect'咑'unionallselect'妸'unionallselect'发'unionallselect'旮'unionallselect'铪'unionallselect'丌'/*becausehaveno'i'*/unionallselect'丌'unionallselect'咔'unionallselect'垃'unionallselect'嘸'unionallselect'拏'unionallselect'噢'unionallselect'妑'unionallselect'七'unionallselect'呥'unionallselect'仨'unionallselect'他'unionallselect'屲'/*no'u'*/unionallselect'屲'/*no'v'*/unionallselect'屲'unionallselect'夕'unionallselect'丫'unionallselect'帀'unionallselect@chn)asaorderbychnCOLLATEChinese_PRC_CI_AS)asbelseset@c=@chnset@return=@return+@cend/*while循环结束*/return(@return)end/*函数实现结束*/然后就可以用了。substring 转换为英文首先字母selectsubstring(dbo.[fn_ChineseToSpell](name),1,1)asfw,*frommemberorderbyfw
如果觉得《SQL中英文混合排序》对你有帮助,请点赞、收藏,并留下你的观点哦!