﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / Need Split delimiter string into columns Solution / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 01:20:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>[quote][b]gauravupadhyay2009 (4/26/2013)[/b][hr]Thanks a lot for writing this wonderful SQL Code. it gave me relax that i could not get 2 days.i used this code in BULK Insert from .txt file data.with delim (|) .thanks againGaurav UpadhyayIndia[/quote]Why would you need to use any of the code on this thread if you used BULK INSERT?  And if  the  code is the WHILE loop code, you may have built in a bit of a performance problem into your code.</description><pubDate>Fri, 26 Apr 2013 09:24:15 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>Thanks a lot for writing this wonderful SQL Code. it gave me relax that i could not get 2 days.i used this code in BULK Insert from .txt file data.with delim (|) .thanks againGaurav UpadhyayIndia</description><pubDate>Fri, 26 Apr 2013 06:45:39 GMT</pubDate><dc:creator>gauravupadhyay</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>Thanks for this function, Paul! :)</description><pubDate>Thu, 21 Mar 2013 07:10:17 GMT</pubDate><dc:creator>Andrius-794186</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>[quote][b]nick.wright 69367 (12/4/2012)[/b][hr]That's great, Sean. Unfortunately, being an "agile" kind of developer, the ink on my code is still wet as it goes into a live environment ;-). The new improved code will have to wait until the next iteration. Fortunately, its in a batch job that runs overnight and performance isn't (yet) an issue. However, I'll read your article and try to learn from it!Thanks, AgainNick Wright[/quote]I hear ya there. Can't always change at the last minute. :-) It isn't my article but one written by Jeff Moden. That article has the ability to completely change the way you think about data. It will present you initially with the concept of a tally table which is probably the most useful technique in a sql developers tool box. Once you fully understand the tally table, the string splitter portion makes total sense.</description><pubDate>Tue, 04 Dec 2012 08:33:30 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>That's great, Sean. Unfortunately, being an "agile" kind of developer, the ink on my code is still wet as it goes into a live environment ;-). The new improved code will have to wait until the next iteration. Fortunately, its in a batch job that runs overnight and performance isn't (yet) an issue. However, I'll read your article and try to learn from it!Thanks, AgainNick Wright</description><pubDate>Tue, 04 Dec 2012 08:23:27 GMT</pubDate><dc:creator>nick.wright 69367</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>[quote][b]nick.wright 69367 (12/4/2012)[/b][hr]Thank you very much for this. I wouldn't normally use a while loop in a function, but looking at the replace/substring code I've written in the past to get, say, the 5th element in a delimited string I'm more than happy to use it here!My only amendment was to add the delimiter as a parameter, to make it more extensible.[/quote]Nick,Unfortunately you found a very old thread with a VERY out of date methodology for splitting delimited strings. Please take a look at the link in my signature for MUCH improved way to split strings in sql.</description><pubDate>Tue, 04 Dec 2012 08:03:05 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>Thank you very much for this. I wouldn't normally use a while loop in a function, but looking at the replace/substring code I've written in the past to get, say, the 5th element in a delimited string I'm more than happy to use it here!My only amendment was to add the delimiter as a parameter, to make it more extensible.</description><pubDate>Tue, 04 Dec 2012 02:11:02 GMT</pubDate><dc:creator>nick.wright 69367</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>&lt;P&gt;Hi Paul / SM,&lt;/P&gt;&lt;P&gt;Thanks for this as well, just what I needed.&lt;/P&gt;&lt;P&gt;Regds,&lt;/P&gt;&lt;P&gt;EP&lt;/P&gt;</description><pubDate>Tue, 18 Oct 2005 05:34:00 GMT</pubDate><dc:creator>Ed Phillips</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;   This works Great!!!! Thanks so much, I have been splitting my hair for this solution...again Thank you!!!&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;SM&lt;/P&gt;</description><pubDate>Fri, 14 Oct 2005 09:22:00 GMT</pubDate><dc:creator>smunshi</dc:creator></item><item><title>RE: Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>I just did something similar the other day with Progress arrays, which are returned to SQL Server as a single semicolon-delimited column, and I needed to split out one such array into several columns.This is the function I wrote... you would need to replace the semicolon (&lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt; with your own delimiter (a slash?).CREATE FUNCTION dbo.FromProgressArray (@array VARCHAR(4000), @index INT)RETURNS VARCHAR(4000)ASBEGINIF @index = 0	RETURN( LEFT(@array, CHARINDEX(';', @array) - 1) )DECLARE @counter INTSELECT @counter = 0WHILE @counter &lt; @indexBEGIN	IF (CHARINDEX(';', @array) &lt;&gt; 0)		SELECT @array = SUBSTRING(@array, CHARINDEX(';', @array) + 1, LEN(@array))	ELSE		SELECT @array = ''	SELECT @counter = @counter + 1ENDIF CHARINDEX(';', @array) != 0	SELECT @array = LEFT(@array, CHARINDEX(';', @array) - 1)RETURN( @array )ENDGOThen you can do this:INSERT INTO table (cat, subcat1, subcat2, subcat3, subcat4, subcat5)SELECT dbo.FromProgressArray(sourcecol, 0), dbo.FromProgressArray(sourcecol, 1), dbo.FromProgressArray(sourcecol, 2), dbo.FromProgressArray(sourcecol, 3), dbo.FromProgressArray(sourcecol, 4), dbo.FromProgressArray(sourcecol, 5)FROM source_tableHTH.</description><pubDate>Fri, 14 Oct 2005 08:50:00 GMT</pubDate><dc:creator>Paul Cresham</dc:creator></item><item><title>Need Split delimiter string into columns Solution</title><link>http://www.sqlservercentral.com/Forums/Topic229031-8-1.aspx</link><description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I need help with a string with delimiter that needs to be split into column names. I have been looking for this solution for a while. Specifically what I want to do is noted below...&lt;/P&gt;&lt;P&gt;Currently:&lt;/P&gt;&lt;P&gt;I have a table with a string with delimiter column, and I need to split this string into columns as shown below: Note that the cat and subcat can vary in length...&lt;/P&gt;&lt;P&gt;'/cat/subcat1/subcat2/subcat3/subcat4/subcat5'&lt;/P&gt;&lt;P&gt;What I need is a t-sql that pivots this list into new columns as shown below:&lt;/P&gt;&lt;P&gt;cat     subcat1   subcat2   subcat3   subcat4   subcat5------  --------  --------  --------  --------  -------- School  Math      Science   History    Arts         PE&lt;/P&gt;&lt;P&gt;Also I need a way to insert these new columns into the existing table that has the original string with delimiter...&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description><pubDate>Fri, 14 Oct 2005 08:34:00 GMT</pubDate><dc:creator>smunshi</dc:creator></item></channel></rss>