SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Parse Text In Column by Underscore
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pattonjo
Starting Member

USA
11 Posts

Posted - 12/02/2013 :  19:51:48  Show Profile  Reply with Quote
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)

Singapore
17593 Posts

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


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/03/2013 :  00:18:17  Show Profile  Reply with Quote

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000