Wednesday, June 18, 2008

[sql] Extract domain from URL

CASE WHEN CHARINDEX('//', url) > 0
THEN SUBSTRING(url,
(CHARINDEX('//', url) +2),
(CASE WHEN CHARINDEX('/', url, CHARINDEX('//', url) +3) > 0
THEN CHARINDEX('/', url, CHARINDEX('//', url) +3)
ELSE (CASE WHEN CHARINDEX('?', url, CHARINDEX('//', url) +3) > 0
THEN CHARINDEX('?', url, CHARINDEX('//', url) +3)
ELSE LEN(url) +1 END)
END)
- (CHARINDEX('//', url) +2))
ELSE '' END

No comments:

Post a Comment