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)
 Split string of concatenated words

Author  Topic 

tdk1964
Starting Member

1 Post

Posted - 2010-12-02 : 09:20:51
I wonder if anyone could help me with a problem I'm having.

I have some data in a table that contains many joined words e.g. ThisIsASample
What I would like to to is change it to read This Is A Sample

I have about 5,000 records and don't want to do it manually but cannot figure out how to do it :(

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-02 : 09:36:21
declare @test varchar(255)
set @test = 'ThisIsATest'

declare @ascii int
set @ascii=65

while @ascii <= 90
begin
set @test = replace(@test collate SQL_Latin1_General_CP1_CS_AS,char(@ascii),' '+char(@ascii))
set @ascii = @ascii + 1
end

set @test = ltrim(@test)

select @test

-- result
-- 'This Is A Test'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-12-02 : 09:40:23
But are you sure the start of the word will be in uppercase for which you want to split the string?

PBUH

Go to Top of Page
   

- Advertisement -