Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Transact-SQL (2008)
 Retrieve specific part from record?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

under2811
Constraint Violating Yak Guru

India
366 Posts

Posted - 03/03/2013 :  01:32:07  Show Profile  Reply with Quote
Experts

I am facing tricky part in sql
My requirement is like to get particular string from the record
In my DB I have records like

Name_col
CN-FCT?AB3457;~XXXXXX;~CN-FCT?AB3458;~YYYYYY;~CN-FCT?AB3459;~ZZZZZZ

I want like
Name_col
XXXXXX;YYYYYY;ZZZZZZ

How could i get that one??

T.I.A

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 03/03/2013 :  02:23:14  Show Profile  Reply with Quote
Some combination of left, mid, substr, charindex and patindex will help here depending on your data and requirements.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 03/03/2013 :  11:30:02  Show Profile  Reply with Quote
You can use a string splitter such as DelimitedSplit8K - see the example below:
declare @col varchar(512) = 'CN-FCT?AB3457;~XXXXXX;~CN-FCT?AB3458;~YYYYYY;~CN-FCT?AB3459;~ZZZZZZ';
select ';'+item from dbo.DelimitedSplit8K(REPLACE(@col,';~',';'),';')
where ItemNumber%2 = 0 for xml path('')
The DelimitedSplit8K is available here: http://www.sqlservercentral.com/articles/Tally+Table/72993/
Go to Top of Page

under2811
Constraint Violating Yak Guru

India
366 Posts

Posted - 03/03/2013 :  18:33:28  Show Profile  Reply with Quote
Thanks a lot!!!!
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 03/03/2013 :  20:46:25  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next 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