转自:http://www.cnblogs.com/zhuisuo/archive/2011/01/12/1933842.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | create function [dbo].[fn_getpy] ( @str nvarchar( 4000 )) returns nvarchar( 4000 ) as begin declare @str_len int , @result nvarchar( 4000 ) , @crs nvarchar( 1 ) set @str_len =len( @str ) set @result = ' ' while @str_len > 0 begin set @crs =substring( @str , @str_len , 1 ) select @str_len = @str_len - 1 , @result = case when @crs >= '帀' then 'Z' when @crs >= '丫' then 'Y' when @crs >= '夕' then 'X' when @crs >= '屲' then 'W' when @crs >= '他' then 'T' when @crs >= '仨' then 'S' when @crs >= '呥' then 'R' when @crs >= '七' then 'Q' when @crs >= '妑' then 'P' when @crs >= '噢' then 'O' when @crs >= '拏' then 'N' when @crs >= '嘸' then 'M' when @crs >= '垃' then 'L' when @crs >= '咔' then 'K' when @crs >= '丌' then 'J' when @crs >= '铪' then 'H' when @crs >= '旮' then 'G' when @crs >= '发' then 'F' when @crs >= '妸' then 'E' when @crs >= '咑' then 'D' when @crs >= '嚓' then 'C' when @crs >= '八' then 'B' when @crs >= '吖' then 'A' else @crs end+ @result end return ( @result ) end |