|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Parse domain name out of URL
I am wondering what is the best way to parse a domain name out of a url string using an sql function (and nothing else). The url could be "http:/www.somename.com/...." or "http://.somename.com/...." or "somename.com/...." As far as I know there is no built in functionality for reg expressions in MS SQL 2000. I was thinking maybe look for the first occurrence of a '.' followed by a '/' and then grab everything before the '/'. Has anyone else done this, and if so, how?
|
|
#2
|
|||
|
|||
|
Hi Kommi!
You are right, there is no such function which may return domain out of a url. Based on your criteria, I have coded a function, I hope this would be helpful for you. --------------------------------------------------------------- CREATE function usp_extract_domain(@chr varchar(255)) returns varchar(255) as BEGIN declare @done bit declare @cnt int declare @subs char(1) declare @starts int declare @ends int set @cnt = len(@chr) --Find a dot(.) set @done=0 while (@cnt<>0 or @done=1) begin set @subs=substring(@chr , @cnt, 1) if (@subs='.') begin set @done=1 break end else set @cnt= @cnt - 1 end if (@done=0) begin return(0) end set @starts=@cnt+1 --Find next set @cnt=len(@chr) set @done=0 while (@cnt<>0 or @done=1) begin set @subs=substring(@chr , @cnt, 1) if (@subs='/') begin set @done=1 break end else set @cnt= @cnt - 1 end if (@starts > @cnt) begin set @cnt=len(@chr) set @ends=@cnt-(@starts-1) end Else set @ends=@cnt-@starts --Return the Result return substring(@chr , @starts , @ends) END -------------------------------------------------------------- If this does not help you, tell me your problem in detail. If helps, don't forget to reply. -Som Dutt |
|
#3
|
|||
|
|||
|
Hi,
You can also try the user defined function Parse_For_Domain_Name for this task at http://www.kodyaz.com/articles/how_...omain_name.aspx Eralper |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Parse domain name out of URL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|