• 转载 sql 首字母大写


    CREATE FUNCTION [dbo].[CapitalizeFirstLetter]
    (
    --string need to format
    @string VARCHAR(200)--increase the variable size depending on your needs.
    )
    RETURNS VARCHAR(200)
    AS
    
    BEGIN
    --Declare Variables
    DECLARE @Index INT,
    @ResultString VARCHAR(200)--result string size should equal to the @string variable size
    --Initialize the variables
    SET @Index = 1
    SET @ResultString = ''
    --Run the Loop until END of the string
    
    WHILE (@Index <LEN(@string)+1)
    BEGIN
    IF (@Index = 1)--first letter of the string
    BEGIN
    --make the first letter capital
    SET @ResultString =
    @ResultString + UPPER(SUBSTRING(@string, @Index, 1))
    SET @Index = @Index+ 1--increase the index
    END
    
    -- IF the previous character is space or '-' or next character is '-'
    
    ELSE IF ((SUBSTRING(@string, @Index-1, 1) =' 'or SUBSTRING(@string, @Index-1, 1) ='-' or SUBSTRING(@string, @Index+1, 1) ='-') and @Index+1 <> LEN(@string))
    BEGIN
    --make the letter capital
    SET
    @ResultString = @ResultString + UPPER(SUBSTRING(@string,@Index, 1))
    SET
    @Index = @Index +1--increase the index
    END
    ELSE-- all others
    BEGIN
    -- make the letter simple
    SET
    @ResultString = @ResultString + LOWER(SUBSTRING(@string,@Index, 1))
    SET
    @Index = @Index +1--incerase the index
    END
    END--END of the loop
    
    IF (@@ERROR
    <> 0)-- any error occur return the sEND string
    BEGIN
    SET
    @ResultString = @string
    END
    -- IF no error found return the new string
    RETURN @ResultString
    END
    I'm fine, it's ok
  • 相关阅读:
    常见的单链表题目
    SpringBoot Hello
    IDEA 重置
    lombok的用法
    软件测试系列白盒测试覆盖率的问题
    软件测试系列软件测试基础
    Linux常用命令1对文件进行查看、复制、移动和分割
    软件测试系列通用测试用例写作
    Java继承特性
    Linux常用命令3如何设置IP地址?如何更改系统时间?
  • 原文地址:https://www.cnblogs.com/skywss27/p/9926232.html
Copyright © 2020-2023  润新知