This is a basic function for Microsoft SQL to generate a proper case name and remove some of the spaces.
create function properCaseName ( @s varchar(255))
returns varchar(255)
as
begin
declare @flag int,@retVal as varchar(255)
select @s=lower(ltrim(rtrim(replace(replace(replace(replace(isnull(@s,''),' ',' '),' ',' '),' ',' '),' ',' '))))
select @retVal='',@flag=len(@s)
while (@flag>0)
begin
select @flag=charindex(' ',@s)
select @retVal=@retVal+upper(left(@s,1))+case @flag when 0 then right(@s,len(@s)-1) else substring(@s,2,@flag-1) end
select @s=right(@s,len(@s)-@flag)
end
select @retVal=ltrim(rtrim(@retVal))
return @retVal
end