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

sql中写标量函数生成大写拼音首字母

时间:2016-08-07 12:22:53      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

USE [StockManageSystemV2]
GO
/****** Object:  UserDefinedFunction [dbo].[PinYin]    Script Date: 2016-08-07 11:19:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[PinYin] ( @STR NVARCHAR(4000) )
RETURNS NVARCHAR(4000)
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 @STRRET;
    END;

 

sql中写标量函数生成大写拼音首字母

标签:

原文地址:http://www.cnblogs.com/wenjieyatou/p/5745821.html

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