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 sql server 2005

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2010-04-07 : 07:51:03
Hi,

I am a parameter that gets a string example: '0976-009,3455-076'.

I need to first split the string where the commas are and than by - as i need to insert the values into a table with 2 columns. The result should be:

style colour
0976 009
3455 076


Any help would be appreciated.

Thanks


Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 07:58:00
Are the parameters always like this? '0976-009,3455-076'
Or is this also possible? '0976-009,3455-076,1234-123,2345-678,9999-878,2222-555'


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

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2010-04-07 : 08:15:17
yea possible also

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 09:00:15
select
parsename(replace(Data,'-','.'),2) as style,
parsename(replace(Data,'-','.'),1) as colour
from dbo.fnParseList(',','0976-009,3455-076,1234-123,2345-678,9999-878,2222-555')

And fnParseList is here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


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

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2010-04-07 : 09:33:41
Thanks works great :-)

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 09:35:36
welcome


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

- Advertisement -