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 2008 Forums
 Analysis Server and Reporting Services (2008)
 Delimit values in a column into rows

Author  Topic 

SlimJimHymns
Starting Member

1 Post

Posted - 2013-04-27 : 16:17:29
Hi,
I having trouble taking the below type of column and delimiting it into rows. See below:

Table1
ID BatchNum
543 455/544/655

Table2
ID BatchNum
543 455
543 544
543 655

Thanks,

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-28 : 08:24:09
You need a string parser - the best one by far that I have seen is Jeff Moden's code here: http://www.sqlservercentral.com/articles/Tally+Table/72993/ Copy the code from Figure 21 in his article to an SSMS query window, and run it - which will install the function. Then use it like this:
select
t.id,
d.Item as BatchNum
from
YourTable t
cross apply
( select * from dbo.DelimitedSplit8K( t.BatchNum,'/')) d
order by
id, ItemNumber;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-29 : 01:00:08
just another way

http://visakhm.blogspot.com/2013/01/delimited-string-split-xml-parsing.html

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

- Advertisement -