分类

链接

2011 年 11 月
 123456
78910111213
14151617181920
21222324252627
282930  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > Others, SQL Server > 正文
共享办公室出租
sql得到中文首字母
Others, SQL Server 暂无评论 阅读(2,350)
USE [JewelryRetailClientDB]GO

/****** Object: UserDefinedFunction [dbo].[Func_GetPY] Script Date: 10/19/2011 14:21:59 ******/SET ANSI_NULLS ONGO

SET QUOTED_IDENTIFIER ONGO

-- =============================================
-- Author: xoyozo-- Create date: 2010-4-17
-- Description: 提供中文首字母
-- =============================================
CREATE FUNCTION [dbo].[Func_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 @PYENDGO

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:sql得到中文首字母 | Bruce's Blog

发表评论

留言无头像?