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 into rows

Author  Topic 

Muj9
Yak Posting Veteran

75 Posts

Posted - 2013-08-06 : 04:54:54
Hi everybody,

I have a column which has data consisting of comments. The problem is that one row should have one comment but i have many rows which hold 2 or 3 comments in a single row. i want to split the comments in to a new row so that each row has a single comment. the comments are split using ; semi colon.

for example:
Comments
I love football
I drive car
I work; i eat; whatever
You get my point


I would like it to be like :-

Comments
I love football
I drive car
I work
i eat
whatever
You get my point

So please any body out there who can help??? Would really appriciate it.

Thanks in Advance



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-06 : 05:40:48
see

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

you can use it like

SELECT f.Val
FROM table t
CROSS APPLY dbo.ParseValues(t.comments,';')f


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Muj9
Yak Posting Veteran

75 Posts

Posted - 2013-08-06 : 06:52:19
Thank you so much it has worked.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-06 : 09:17:28
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -