且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server:使所有大写字母变为适当的大小写/标题大小写

更新时间:2023-02-15 17:28:49

这是可以解决问题的UDF ...

Here's a UDF that will do the trick...

create function ProperCase(@Text as varchar(8000))
returns varchar(8000)
as
begin
  declare @Reset bit;
  declare @Ret varchar(8000);
  declare @i int;
  declare @c char(1);

  if @Text is null
    return null;

  select @Reset = 1, @i = 1, @Ret = '';

  while (@i <= len(@Text))
    select @c = substring(@Text, @i, 1),
      @Ret = @Ret + case when @Reset = 1 then UPPER(@c) else LOWER(@c) end,
      @Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,
      @i = @i + 1
  return @Ret
end

尽管如此,您仍然必须使用它来更新数据.

You will still have to use it to update your data though.