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
 Transact-SQL (2008)
 Retrieve specific part from record?

Author  Topic 

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2013-03-03 : 01:32:07
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 - 2013-03-03 : 02:23:14
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-03 : 11:30:02
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

366 Posts

Posted - 2013-03-03 : 18:33:28
Thanks a lot!!!!
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-03 : 20:46:25
You are very welcome - glad to help.
Go to Top of Page
   

- Advertisement -