Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Is there any built in function for init cap

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-07-22 : 05:40:25
I have data Like
FEDERATED STATES OF MICRONESIA

and I want's it to change into

Federated States Of Micronesia

is there any built in function which i can use to update data in my table

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-22 : 05:42:26
No. there isn't any.

Search the script library for this.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-07-22 : 05:59:10
I found this way.You can write some function which will accept the row value & will give you the formatted value the way you want.

declare @var varchar(500)
set @var='FEDERATED STATES OF MICRONESIA'
declare @xml as xml
set @xml= '<i>'+ replace(@var,' ','</i><i>') + '</i>'
select @xml

declare @x as table(value varchar(50))
insert into @x
select left(x.i.value('.','varchar(50)'),1)
+ '' + lower(right(x.i.value('.','varchar(50)'),
len(x.i.value('.','varchar(50)'))-1))
from @xml.nodes('/i')x(i)
select cast(value + ' ' as varchar(50)) from @x for xml path('')
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-07-22 : 06:16:14
Here's my contribution (I've just seen ayamas's and it's the same basic idea)...

--variable example
declare @x varchar(50)
set @x = 'FEDERATED STATES OF MICRONESIA'

select @x as x,
replace((select case when N = 1 or substring(@x, N-1, 1) = ' '
then upper(substring(@x, N, 1))
else lower(substring(@x, N, 1)) end
from dbo.Tally b
where b.N <= len(@x)
for xml path(''))
, '#x20;', ' ') as CamelCase

--table select example
declare @t table (x varchar(50) not null)

insert @t
select 'FEDERATED STATES OF MICRONESIA'
union all select 'another ONE'
union all select 'YeT aNoThEr OnE'

select x,
replace((select case when N = 1 or substring(a.x, N-1, 1) = ' '
then upper(substring(a.x, N, 1))
else lower(substring(a.x, N, 1)) end
from dbo.Tally b
where b.N <= len(a.x)
for xml path(''))
, '#x20;', ' ') as CamelCase
from @t a

--table update example
update a set x =
replace((select case when N = 1 or substring(a.x, N-1, 1) = ' '
then upper(substring(a.x, N, 1))
else lower(substring(a.x, N, 1)) end
from dbo.Tally b
where b.N <= len(a.x)
for xml path(''))
, '#x20;', ' ')
from @t a

select * from @t


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-07-22 : 06:18:05
Oh, and see this link for the tally table and many of its uses:

http://www.sqlservercentral.com/articles/TSQL/62867/


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-07-23 : 02:56:59
--

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-23 : 03:21:07
quote:
Originally posted by kamii47

--

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com



What was your reply?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -