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
 Parse text in a string

Author  Topic 

s_anr
Yak Posting Veteran

81 Posts

Posted - 2010-12-02 : 19:33:10
I have a column with these values

The Website is mysite1.com because it is my site.
The Website is hissite2.com because it is his site.
The Website is yoursite3.com because it is your site.
The Website is mysite4.com because it isn't my site.
The Website is hersite5.com because this is her site.

How do I extract only website name

mysite1.com
hissite2.com
yoursite3.com
mysite4.com
hersite5.com
Logically I should be able to capture text between 'The Website is ' and ' because'. I know its possible using substring functions but I couldn't figure out. Any help?

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2010-12-02 : 20:33:28
Try this:

SELECT SUBSTRING(your_column,
LEN('The Website is') + 2,
CHARINDEX(' because ', your_column) -
LEN('The Website is') - 2),
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2010-12-03 : 06:34:54
malpashaa..your query works fine
Go to Top of Page

s_anr
Yak Posting Veteran

81 Posts

Posted - 2010-12-03 : 15:27:20
Thanks malpashaa. It works...
Go to Top of Page
   

- Advertisement -