sql 将英文句子中的单词首字母转换为大写


create function dbo.pTitleCase
(
@StrIn nvarchar(max)
)
returns nvarchar(max)
as
begin;
declare @StrOut nvarchar(max),
@CurrentPosition int,
@NextSpace int,
@CurrentWord nvarchar(max),
@StrLen int,
@LastWord bit;

set @NextSpace=1;
set @CurrentPosition=1;
set @StrOut='';
set @StrLen=len(@StrIn);
set @LastWord=0;

while @LastWord=0
begin;
set @NextSpace=charindex(' ',@StrIn,@CurrentPosition+1);
if @NextSpace=0
begin;
set @LastWord=1;
set @NextSpace=@StrLen;
end;
set @CurrentWord=upper(substring(@StrIn,@CurrentPosition,1));
set @CurrentWord=@CurrentWord+lower(substring(@StrIn,@CurrentPosition+1,@NextSpace-@CurrentPosition));
set @StrOut=@StrOut+@CurrentWord;
set @CurrentPosition=@NextSpace+1;
end;
return @StrOut;
end;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM