SQL Server:使所有大写字母变为适当的大小写/标题大小写 [英] SQL Server: Make all UPPER case to Proper Case/Title Case
本文介绍了SQL Server:使所有大写字母变为适当的大小写/标题大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个作为所有大写字母导入的表,我想将其转换为大写字母.你们使用什么脚本来完成此任务?
I have a table that was imported as all UPPER CASE and I would like to turn it into Proper Case. What script have any of you used to complete this?
推荐答案
这是可以解决问题的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.
这篇关于SQL Server:使所有大写字母变为适当的大小写/标题大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文