码迷,mamicode.com
首页 > 其他好文 > 详细

字母转为大写字母

时间:2019-05-31 21:53:02      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:value   function   code   定义   play   tle   span   大写   case   

 自定义Scalar-valued Function函数,把字母转换为大写字母。

字母转为大写字母a-->A;b-->B;c-->C;...z-->Z
如果非字母转换为‘‘

 

技术图片

 

技术图片
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      Insus.NET
-- Blog:        https://insus.cnblogs.com
-- Create date: 2019-05-31
-- Update date: 2019-05-31
-- Description: 字母转为大写字母a-->A;b-->B;c-->C;...z-->Z
--              如果非字母转换为‘‘
-- =============================================
CREATE FUNCTION [dbo].[svf_ConvertLettertoUppercaseLetter] 
(
  @Letter CHAR(1)
) RETURNS CHAR(1)
AS
BEGIN
    DECLARE @UppercaseLetter CHAR(1) = ‘‘          
    IF LEN(ISNULL(@Letter,‘‘)) > 0 
    BEGIN
        IF ASCII(@Letter) % 97 + 1 <= 26
            SET @UppercaseLetter = CHAR(ASCII(@Letter) - (97 - 65)) 

        IF ASCII(@Letter) % 65 + 1 <= 26
            SET @UppercaseLetter = @Letter
    END      
    RETURN @UppercaseLetter
END
GO
Source Code

 

例子演示:

技术图片

 

技术图片
SELECT
[dbo].[svf_ConvertLettertoUppercaseLetter] (A) AS A,
[dbo].[svf_ConvertLettertoUppercaseLetter] (a) AS a,
[dbo].[svf_ConvertLettertoUppercaseLetter] (B) AS B,
[dbo].[svf_ConvertLettertoUppercaseLetter] (b) AS b,
[dbo].[svf_ConvertLettertoUppercaseLetter] (C) AS C,
[dbo].[svf_ConvertLettertoUppercaseLetter] (c) AS c,
[dbo].[svf_ConvertLettertoUppercaseLetter] (Z) AS Z,
[dbo].[svf_ConvertLettertoUppercaseLetter] (z) AS z,
[dbo].[svf_ConvertLettertoUppercaseLetter] ($) AS $
Source Code

 

字母转为大写字母

标签:value   function   code   定义   play   tle   span   大写   case   

原文地址:https://www.cnblogs.com/insus/p/10957431.html

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