生成文字首字母拼音码标量函数
--生成拼音首码 CREATE FUNCTION [dbo].[fn_GetPy] (@str nvarchar(4000)) returns nvarchar (4000) --WITH ENCRYPTION AS BEGIN DECLARE @intLen INT DECLARE @strRet nvarchar (4000) DECLARE @temp nvarchar (100) SET @intLen = len(@str) SET @strRet = '' WHILE @intLen > 0 BEGIN SET @temp = '' SELECT @temp = CASE WHEN SUBSTRING (@str ,@intLen, 1) >= '帀' THEN 'Z' WHEN SUBSTRING (@str ,@intLen, 1) >= '丫' THEN 'Y' WHEN SUBSTRING (@str ,@intLen, 1) >= '夕' THEN 'X' WHEN SUBSTRING (@str ,@intLen, 1) >= '屲' THEN 'W' WHEN SUBSTRING (@str ,@intLen, 1) >= '他' THEN 'T' WHEN SUBSTRING (@str ,@intLen, 1) >= '仨' THEN 'S' WHEN SUBSTRING (@str ,@intLen, 1) >= '呥' THEN 'R' WHEN SUBSTRING (@str ,@intLen, 1) >= '七' THEN 'Q' WHEN SUBSTRING (@str ,@intLen, 1) >= '妑' THEN 'P' WHEN SUBSTRING (@str ,@intLen, 1) >= '噢' THEN 'O' WHEN SUBSTRING (@str ,@intLen, 1) >= '拏' THEN 'N' WHEN SUBSTRING (@str ,@intLen, 1) >= '嘸' THEN 'M' WHEN SUBSTRING (@str ,@intLen, 1) >= '垃' THEN 'L' WHEN SUBSTRING (@str ,@intLen, 1) >= '咔' THEN 'K' WHEN SUBSTRING (@str ,@intLen, 1) >= '丌' THEN 'J' WHEN SUBSTRING (@str ,@intLen, 1) >= '铪' THEN 'H' WHEN SUBSTRING (@str ,@intLen, 1) >= '旮' THEN 'G' WHEN SUBSTRING (@str ,@intLen, 1) >= '发' THEN 'F' WHEN SUBSTRING (@str ,@intLen, 1) >= '妸' THEN 'E' WHEN SUBSTRING (@str ,@intLen, 1) >= '咑' THEN 'D' WHEN SUBSTRING (@str ,@intLen, 1) >= '嚓' THEN 'C' WHEN SUBSTRING (@str ,@intLen, 1) >= '八' THEN 'B' WHEN SUBSTRING (@str ,@intLen, 1) >= '吖' THEN 'A' ELSE rtrim( ltrim(SUBSTRING(@str ,@intLen, 1)) ) END --对于汉字特殊字符,不生成拼音码 IF (ascii(@temp) > 127) SET @temp = '' --对于英文中小括号,不生成拼音码 IF @temp = '(' OR @temp = ')' SET @temp = '' SELECT @strRet = @temp + @strRet SET @intLen = @intLen - 1 END RETURN LOWER (@strRet) end