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
 General SQL Server Forums
 New to SQL Server Programming
 Split Data

Author  Topic 

nirene
Yak Posting Veteran

98 Posts

Posted - 2009-11-06 : 01:23:01
Hai,
I just want to split data into 4 columns, and the delimiter is ||

VP-Inter State || 17888F8068877DRZ || Palio Stile SDX || 51448.3

Regards

Nirene

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-06 : 01:48:52
Not the best way but I could not resist to use parsename:
declare @test varchar(255)
set @test = 'VP-Inter State || 17888F8068877DRZ || Palio Stile SDX || 51448.3'

select ltrim(rtrim(replace(parsename(replace(replace(@test,'.','~'),'||','.'),4),'~','.')))
select ltrim(rtrim(replace(parsename(replace(replace(@test,'.','~'),'||','.'),3),'~','.')))
select ltrim(rtrim(replace(parsename(replace(replace(@test,'.','~'),'||','.'),2),'~','.')))
select ltrim(rtrim(replace(parsename(replace(replace(@test,'.','~'),'||','.'),1),'~','.')))



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

nirene
Yak Posting Veteran

98 Posts

Posted - 2009-11-06 : 02:07:16
Thanks a lot

Nirene
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-06 : 02:41:05
or
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/03/15/splitting-csv-to-columns.aspx

Madhivanan

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

- Advertisement -