Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

SQL Server Convert String to Proper Case (Camel Case) or Title Case Function Example

Sep 8, 2015
Introduction:

Here I will explain how to convert string to proper case or title case or camel case in
sql server with example. To convert string to proper case or title case in sql server we don’t have any built in function for that we need to create user defined functions to convert string to title case in sql server.
Description:

To call stored procedure from another stored procedure with parameters in sql server follow below steps

Create New Function fn_titlecase in database


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

Once you create function in database execute following query it will return data string in title case or proper case or camel case in sql server.


-- Execute this query to convert string to title case / proper case in sql server
select dbo.fn_titlecase('hi, welcome to aspdotnet-suresh.com')

If we execute above query we will get output like as shown below

Output


Output of SQL Server Convert String to Proper Case (Camel Case) or Title Case Function Example


I hope it helps you to convert string to proper case or camel case or title case in sql server.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Anonymous said...

You are simply awwwwwwwesome.....all your posts are very useful for beginners and students...I have learnt lot of from here.

Thanks.

Anonymous said...

Very Nice

Anonymous said...

Hi. I have large database that user entered small/capital letters are mixed. Is it possible to change the data like '[a-zA-Z]'. coz there are above 60,000 rows and 18 columns. I need change in address and Name.?

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.