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.
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:
In
previous articles I explained single stored procedure to create, update, delete operations in
sql server, SQL Server insert multiple records
with one insert statement, SQL Server restore database from
.bak / .mdf file, SQL Server single procedure to
insert update delete, SQL Server take database backup, Primary key constraint in sql
server,
foreign key constraint in sql
server,
cursor example in sql server and many articles relating to SQL
server.
Now I will explain how to convert string to title case in sql
server
with example.
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
|
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. |
|||
|
|||
3 comments :
You are simply awwwwwwwesome.....all your posts are very useful for beginners and students...I have learnt lot of from here.
Thanks.
Very Nice
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.?
Note: Only a member of this blog may post a comment.