实现首字母或拼音检索-sql语句方式

 
 
create function [dbo].[fn_GetPY](@str nvarchar(max),@type int)  
returns nvarchar(max)  
as 
begin 

 if(@type=1) 
 begin
            DECLARE @WORD NCHAR(1),@PY NVARCHAR(4000) 
            SET @PY='' 
            WHILE LEN(@STR)>0 
            BEGIN 
            SET @WORD=LEFT(@STR,1) 
            --如果非漢字字符﹐返回原字符 
            SET @PY=@PY+(CASE WHEN UNICODE(@WORD) BETWEEN 19968 AND 19968+20901 
            THEN ( 
            SELECT TOP 1 PY 
            FROM 
            ( 
                SELECT 'A' AS PY,N'' AS WORD 
                UNION ALL SELECT 'B',N'簿' 
                UNION ALL SELECT 'C',N'' 
                UNION ALL SELECT 'D',N'' 
                UNION ALL SELECT 'E',N'' 
                UNION ALL SELECT 'F',N'' 
                UNION ALL SELECT 'G',N'' 
                UNION ALL SELECT 'H',N'' 
                UNION ALL SELECT 'J',N'' 
                UNION ALL SELECT 'K',N'' 
                UNION ALL SELECT 'L',N'' 
                UNION ALL SELECT 'M',N'' 
                UNION ALL SELECT 'N',N'' 
                UNION ALL SELECT 'O',N'' 
                UNION ALL SELECT 'P',N'' 
                UNION ALL SELECT 'Q',N'' 
                UNION ALL SELECT 'R',N'' 
                UNION ALL SELECT 'S',N'' 
                UNION ALL SELECT 'T',N'' 
                UNION ALL SELECT 'W',N'' 
                UNION ALL SELECT 'X',N'' 
                UNION ALL SELECT 'Y',N'' 
                UNION ALL SELECT 'Z',N'' 
            ) T 
            WHERE WORD>=@WORD COLLATE CHINESE_PRC_CS_AS_KS_WS 
            ORDER BY PY ASC 
            ) 
            ELSE @WORD 
            END) 
            SET @STR=RIGHT(@STR,LEN(@STR)-1) 
            END 
            RETURN @PY 

 end 
 


 declare @re nvarchar(max),@crs nvarchar(10)  
 declare @strlen int  
 select @strlen=len(@str),@re='' 
 while @strlen>0  
 begin   
  set @crs= substring(@str,@strlen,1)  
      select @re=  
        CASE  
        when @crs<'' COLLATE Chinese_PRC_CS_AS_KS_WS then @crs  
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'A' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'An' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ba' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ban' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ben' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Beng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Biao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bing' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bo' 
        when @crs<='簿' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Bu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ca' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Can' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ce' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ceng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cha' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Che' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cheng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chuai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chuang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Chuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ci' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cui' 
        when @crs<='籿' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Cuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Da' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'De' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Den' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Deng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Di' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dia' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Diao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Die' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ding' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Diu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Du' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Duan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Dun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Duo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'E' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'En' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Eng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Er' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fa' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Feng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Fu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ga' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ge' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Geng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gu' 
        when @crs<='詿' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gua' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Guai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Guan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Guang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Gun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Guo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ha' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Han' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'He' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Heng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hua' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Huai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Huan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Huang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Hun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Huo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ji' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jia' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jiang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jiao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jing' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jiong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jiu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ju' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Juan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jue' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Jun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ka' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ke' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ken' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Keng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ku' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kua' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kuai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kuang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Kuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'La' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Le' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Leng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Li' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lia' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Liang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Liao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ling' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Liu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Long' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lv' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Luan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lue' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Lun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Luo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ma' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Man' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Me' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Men' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Meng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Miao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Min' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ming' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Miu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Mu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Na' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ne' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Neng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ni' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Niang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Niao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ning' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Niu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nv' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nue' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Nuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'O' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pa' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Peng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Piao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ping' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Po' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Pu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qia' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qiang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qiao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qing' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qiong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qiu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Quan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Que' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Qun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ran' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Rang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Rao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Re' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ren' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Reng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ri' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Rong' 
        when @crs<='嶿' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Rou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ru' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ruan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Rui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Run' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ruo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sa' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'San' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Se' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Seng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sha' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'She' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sheng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shua' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shuai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shuang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Shuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Si' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Song' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Su' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Suan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Sun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Suo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ta' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Te' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Teng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ti' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tiao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ting' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Tuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wa' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Weng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Wu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xia' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xian' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xiang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xiao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xie' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xing' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xiong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xiu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xue' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Xun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ya' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ye' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yin' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ying' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'You' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yue' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Yun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Za' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Ze' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zei' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zen'  
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zeng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zha' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhao' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhe' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhen' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zheng' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhua' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhuai' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhuang' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zhuo' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zi' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zong' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zou' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zu' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zuan' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zui' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zun' 
        when @crs<='' COLLATE Chinese_PRC_CS_AS_KS_WS then 'Zuo' 
        else  @crs end+@re,@strlen=@strlen-1   
   end 
 return(@re)  
END 

调用如下:

select dbo.fn_getpy(realname,0) as quanpin,dbo.fn_getpy(realname,1) as shouzimu,realname,depart from staff

 

posted @ 2017-06-08 10:19  望峰游云  阅读(1216)  评论(0编辑  收藏  举报