怎么用SQL将用户的英文名首字母转为大写?
/*
version: 1.0
createdtime: 2007-01-08
creator: 走过四季
memo: for my lover[hjm]
举列:将用户表〔tbluser〕中〔username〕字段的每个单词首字母大写:
update tbluser set username=dbo.f_Trans(username)
提示:如需使用,请保留以上说明
*/
create function f_Trans(@col varchar(2000))
returns varchar(2000)
as
begin
set @col=replace(@col,' ',' ')
set @col=replace(@col,',','**,')
set @col=replace(@col,' ',',')
declare @sql varchar(2000)
set @sql=''
while charindex(',',@col)>0
select @sql=@sql+upper(left(@col,1))+LOWER(replace(substring(@col,2,charindex(',',@col)-1),',',' ')),
@col=substring(@col,charindex(',',@col)+1,len(@col)-charindex(',',@col))
set @sql=@sql+upper(left(@col,1)) + replace(LOWER(right(@col,len(@col)-1)),',',' ')
set @sql=replace(@sql,'** ',',')
set @sql=replace(@sql,',,',', ')
return(@sql)
end
go
赞1
踩0