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