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
 String Modification

Author  Topic 

mawar76
Starting Member

2 Posts

Posted - 2009-03-19 : 05:11:48
Hi Guys

I'm doing a grouping based on the URL domain.
Can you guys help me to edit string of the URL http://www.google.com/page1.html to become www.google.com

What functions/syntax should I be exploring here for this task?

TQ

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-19 : 05:24:19
[code]DECLARE @Sample TABLE
(
url VARCHAR(200)
)

INSERT @Sample
SELECT 'http://www.google.com/page1.html' UNION ALL
SELECT 'http://www.sqlteam.com' UNION ALL
SELECT 'www.developerworkshop.net'

SELECT url,
SUBSTRING(url, case when f = 0 then 1 else f + 3 end, case when e = 0 then len(url) else e - 1 end)
FROM (
SELECT url,
CHARINDEX('://', url) AS f,
CHARINDEX('/', SUBSTRING(url, CHARINDEX('://', url) + 3, 200)) AS e
FROM @Sample
) AS d[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

mawar76
Starting Member

2 Posts

Posted - 2009-03-19 : 07:22:39
Thanks peso..

your scripts works...
Go to Top of Page
   

- Advertisement -