存储过程左侧的大写第一个字母 [英] Stored Procedure Upper case first letter to the left
本文介绍了存储过程左侧的大写第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个问题,我有一个
的字符串
Hi all ,
i have a question , ihave a String which is
' the quick brown fox jumps over the lazy dog'
在我的存储过程中,我想创建一个像这样的输出
and in my Stored Procedure i want to create an Output like this
' The Quick Brown Fox Jumps Over The Lazy Dog'
我的脚本看到的是"(空格),我会将第一个字母转换为大写.
谢谢大家.
ones my Script see a '' '' (Space) i will convert the first letter to Upper case.
Thanks all.
推荐答案
首先按如下所示创建一个函数并使用它.
它以字符串形式输入输入值,并找到空格并将下一个文本作为大写字母添加到空格.
First Create a Function as below and use the same.
It takes the input value in a string and it finds the white space and make the next text to white space as Upper case.
CREATE FUNCTION FN_TITLECASE (@INPUTSTR VARCHAR(250))
RETURNS VARCHAR(250)
AS BEGIN
DECLARE @TEMPSTR VARCHAR(250)
DECLARE @I INT
SET @TEMPSTR = LOWER(@INPUTSTR)
SET @TEMPSTR = UPPER(LEFT(@TEMPSTR,1)) + SUBSTRING(@TEMPSTR,2,LEN(@TEMPSTR))
WHILE CHARINDEX(' ',@TEMPSTR,1) > 0
BEGIN
SET @I = CHARINDEX(' ',@TEMPSTR,1)
SET @TEMPSTR = LEFT(@TEMPSTR,@I-1) + '~*' + UPPER(SUBSTRING(@TEMPSTR,@I + 1,1)) +SUBSTRING(@TEMPSTR,@I+2,LEN(@TEMPSTR))
END
SET @TEMPSTR = REPLACE(@TEMPSTR,'~*',' ')
SET @INPUTSTR = @TEMPSTR
RETURN @INPUTSTR
END
SELECT DBO.FN_TITLECASE('I GOT YOUR REQUIREMENT KINDLY MAKE A NOTE')
您好,
我已经尝试过此存储过程,可以参考以下内容:
Hello,
I have tried this Stored Procedure , you can refer this:
Create procedure dbo.titleupcase @str varchar(30)
as
begin
Declare @i int, @len int, @newstr varchar(30),@new varchar(30),@space int
set @i=1
set @newstr=''
set @space=1
select @len=len(@str)
while (@i<=@len )
begin
if (@space=1)
begin
Select @new= upper(substring(@str,@i,1))
set @space=0
end
else
begin
Select @new= substring(@str,@i,1)
end
if (@new='')
begin
set @space=1
end
set @newstr=@newstr+@new
set @i=@i+1
end
select @newstr
end
这篇关于存储过程左侧的大写第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文