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
 SQL Server Administration (2008)
 Parse Text In Column by Underscore

Author  Topic 

pattonjo
Starting Member

11 Posts

Posted - 2013-12-02 : 19:51:48
I have a table with column name 'Descrip'as Text. The values look something like this.

1"_(1.000")_Round_6061-T6_CF_12'_(144")

How can I run a query against this table to separate each given underscore and put them in different columns?

1" | (1.000") | Round | 6061-T6 | CF | 12' | (144")

Thanks In Advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-02 : 19:56:47
use fnParseString() from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-03 : 00:18:17
[code]
SELECT MAX(CASE WHEN f.ID = 1 THEN f.Val END) AS Part1,
MAX(CASE WHEN f.ID = 2 THEN f.Val END) AS Part2,
MAX(CASE WHEN f.ID = 3 THEN f.Val END) AS Part3,
MAX(CASE WHEN f.ID = 4 THEN f.Val END) AS Part4,
MAX(CASE WHEN f.ID = 5 THEN f.Val END) AS Part5,
MAX(CASE WHEN f.ID = 6 THEN f.Val END) AS Part6,
MAX(CASE WHEN f.ID = 7 THEN f.Val END) AS Part7
FROM Table t
CROSS APPLY dbo.ParseValues(t.Column,'_')f
GROUP BY t.Column
[/code]

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

- Advertisement -