码迷,mamicode.com
首页 > 数据库 > 详细

汉字拼音首字母查询 Sql Function

时间:2017-11-08 16:01:20      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:logs   begin   declare   else   varchar   blog   span   ansi   拼音   

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[F_SYS_getPY]
(
@str NVARCHAR(4000)
)
RETURNS NVARCHAR(4000)
AS
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


GO

 

汉字拼音首字母查询 Sql Function

标签:logs   begin   declare   else   varchar   blog   span   ansi   拼音   

原文地址:http://www.cnblogs.com/kuojiang/p/7804283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!