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
 Trim
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

satheesh
Posting Yak Master

United Kingdom
146 Posts

Posted - 06/17/2014 :  10:46:42  Show Profile  Reply with Quote
Hi

I have field 'Destination' as below

Destination
>\nDestination: AreaTwo<br />\n<br />\n------<br />\n*Found Re
26<br />\nDestination: AreaOne<br />\n<br />\n------<br />\n*F
/>\nDestination: AreaTwo<br />\n<br />\n------<br />\n*Found R

I have to remove all character before 'Destination:' and after '<br />\n'

i.e i need output like below

Destination
AreaTwo
AreaOne
AreaTwo

How to remove these character. Any help will be highly appreciated.

Thanks

Regards,
SG

Ifor
Aged Yak Warrior

583 Posts

Posted - 06/17/2014 :  11:35:14  Show Profile  Reply with Quote

WITH StartStr
AS
(
	SELECT SUBSTRING(Destination, CHARINDEX('Destination:', Destination) + 13, 255) AS Destination
	FROM YourTable
)
SELECT LEFT(Destination, CHARINDEX('<br />\n', Destination) -1) AS Destination
FROM StartStr;
Go to Top of Page

sz1
Constraint Violating Yak Guru

United Kingdom
440 Posts

Posted - 06/17/2014 :  11:57:12  Show Profile  Reply with Quote
Select Substring(yourfield,4,11) as n1,
Substring(yourfield, 17, 7) as n2,
Substring(yourfield, 88, 7) as n3,
Substring(yourfield, 146,7) as n4
From dbo.YourTable


We are the creators of our own reality!

Edited by - sz1 on 06/17/2014 11:59:27
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/21/2014 :  05:22:55  Show Profile  Reply with Quote

SELECT STUFF(LEFT(Destination, CHARINDEX('<br />\n', Destination + '<br />\n') -1),1,CHARINDEX('Destination:',Destination)+13,'') AS Destination
FROM StartStr


------------------------------------------------------------------------------------------------------
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.05 seconds. Powered By: Snitz Forums 2000