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 2000 Forums
 Transact-SQL (2000)
 Strip information from URL

Author  Topic 

raisor
Starting Member

28 Posts

Posted - 2004-05-22 : 10:37:38
Hello there
I'm receiving URLS from various people, and now would like to know how I can strip off the information in an url to the BASE domain name.

As an example, I would get supplied:
http://www.democraticunderground.com/discuss/duboard.php?az=show_topics&forum=104

Now I would like to strip it to this:
http://www.democraticunderground.com/ OR
http://www.democraticunderground.com

Could someone tell me how I can accomplish this?

Thanks!

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-05-22 : 11:53:23
declare @url varchar(255)
set @url = 'http://www.democraticunderground.com/discuss/duboard.php?az=show_topics&forum=104'

select left(@url,charindex('/',substring(@url,8,255) + '/') + 6)

Result:
http://www.democraticunderground.com

Searches for first / after initial 6 characters (http://) and returns charactes up to that /
If your url's start with something other than http:// (https://, ftp:// or others) this would have to be done differently.


Go to Top of Page

raisor
Starting Member

28 Posts

Posted - 2004-05-22 : 14:02:16
THANKS!!!!!!, works freaking great

Geeez, now you just made me realize indeed about the https:// and ftp and RM streams over rtps (ow actually, that one would works :S)

any hints please :D

Go to Top of Page

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-05-22 : 14:54:34
Try this:

declare @url varchar(255)
set @url = 'http://www.democraticunderground.com/discuss/duboard.php?az=show_topics&forum=104'
select left(@url,charindex('//',@url)+1) + left(substring(@url + '/',charindex('//',@url+'/') + 2,255),charindex('/',substring(@url+'/',charindex('//',@url+'/') + 2,255)) -1)

That will work for anything containing <any characters>//<any characters>

Go to Top of Page

raisor
Starting Member

28 Posts

Posted - 2004-05-23 : 04:31:39
Thank you very much for your help, I'm going to try it out in a bit!, this is great!
Go to Top of Page
   

- Advertisement -