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
 General SQL Server Forums
 New to SQL Server Programming
 Trim

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2014-06-17 : 10:46:42
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

700 Posts

Posted - 2014-06-17 : 11:35:14
[code]
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;
[/code]
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-06-17 : 11:57:12
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!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-06-21 : 05:22:55
[code]
SELECT STUFF(LEFT(Destination, CHARINDEX('<br />\n', Destination + '<br />\n') -1),1,CHARINDEX('Destination:',Destination)+13,'') AS Destination
FROM StartStr
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -