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
 General SQL Server Forums
 New to SQL Server Programming
 parsing the columns data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

anjali5
Yak Posting Veteran

72 Posts

Posted - 05/18/2012 :  19:12:48  Show Profile  Reply with Quote
Hi All,

I have the data below in col1


col1
AB:5          
AB:9 EF:5        
EF:180                    
CD:12 AB:12   


I want top parse it as below.


Col1               AB       CD       EF
AB:5               5
AB:9 EF:5          9                 5
EF:180                              180
CD:12 AB:12        12       12      



How can I acheive this

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/18/2012 :  22:59:25  Show Profile  Reply with Quote

select	col1,
	case 	when col1 like '%AB%'
		then substring(col1, charindex('AB', col1) + 3, charindex(' ', col1 + ' ', charindex('AB', col1)) - charindex('AB', col1) - 3)
		end,
	case 	when col1 like '%CD%'
		then substring(col1, charindex('CD', col1) + 3, charindex(' ', col1 + ' ', charindex('CD', col1)) - charindex('CD', col1) - 3)
		end,
	case 	when col1 like '%EF%'
		then substring(col1, charindex('EF', col1) + 3, charindex(' ', col1 + ' ', charindex('EF', col1)) - charindex('EF', col1) - 3)
		end
from	tbl



KH
Time is always against us

Go to Top of Page

anjali5
Yak Posting Veteran

72 Posts

Posted - 06/28/2012 :  13:54:42  Show Profile  Reply with Quote
Thanks!!
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.06 seconds. Powered By: Snitz Forums 2000