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 2000 Forums
 SQL Server Development (2000)
 Spliting this string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-11 : 08:16:01
Mike writes "I have a table in a database. It has an ID and a string with delimiters.

ID STRING
-- -------
1 Great:Not Great ; Wonderful:Not Wonderful
2 New:Old ; Broken:Fixed


I can use the SUBSTRING to get the first set, but on the last set.

Split1 Split2 Split3
------ --------- -------
Great Not Great Wonderful:Not Wonderful
New Old Broken:Fixed


There are two delimiters, one for the group ";" and the other for the pair ":". It is also possible to have X number of groups in the row. How would I parse this into separate rows to look like something below?

Split1 Split2 Split3 Split4
------ --------- ------- ------
Great Not Great Wonderful Not Wonderful
New Old Broken Fixed

Thank you!
Mike"

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-11 : 10:50:43
Write ur own function to do the task.
Check for the String related functions in BOL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-12 : 03:22:36
Properly normalise the table so that you dont have to store comma delimited values
http://www.datamodel.org/NormalizationRules.html

Refer this split function that returns as rows
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

To return in columns, refer ParseName in BOL, SQL Server help file

Madhivanan

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

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2006-01-12 : 03:24:03
I have put some functions here [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50044[/url] that may start you off. There are also some other links in that thread that you may find useful



steve

-----------

Facts are meaningless. You could use facts to prove anything that's even remotely true!
Go to Top of Page
   

- Advertisement -