Category >
MSSQLSERVER
|| Published on :
Friday, November 6, 2015 || Views:
4173
||
MS-SQL Server Convert String to Proper Case (Camel Case) or Title Case Function Example
Step 1: Open MS-SQL Server
Step 2: Select a database
Step 2: Create a function with the following codes:-
-- www.sourcecodehub.com ---
create function fn_titlecase(@str as varchar(1000))
returns varchar(1000)
as
begin
declare @bitval bit;
declare @result varchar(1000);
declare @i int;
declare @j char(1);
select @bitval = 1, @i=1, @result = '';
while (@i <= len(@str))
select @j= substring(@str,@i,1),
@result = @result + case when @bitval=1 then UPPER(@j) else LOWER(@j) end,
@bitval = case when @j like '[a-zA-Z]' then 0 else 1 end,
@i = @i +1
return @result
end
HOW TO USE:-
-- Execute this query to convert string to title case / proper case in sql server
select dbo.fn_titlecase('Hi this is bill gates')
so, we have learned how to use MS-SQL Server Convert String to Proper Case (Camel Case) or Title Case Function Example