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;

上一篇:java转换unicode,筛选文件中的insert语句并把日期给转换为可以直接在数据库执行的语句


下一篇:YTU 2760: 字符串---首字母变大写