Hi
do you know incase a script which extracts domain names from an email address
like foreg. we have xyz@dmc.com or abce@dmc-int.com
should give
dmc and
dmc-int
Hi
do you know incase a script which extracts domain names from an email address
like foreg. we have xyz@dmc.com or abce@dmc-int.com
should give
dmc and
dmc-int
declare
@email varchar(50),@domain
varchar(50)set
@email = 'johndoe@whatever.com'set
@domain = substring(@email, charindex('@', @email)+1, 50)
Regards Gert-Jan
Close, but that still includes .com
declare @email varchar(50),
@domain varchar(50)
set @email = 'johndoe@whatever.com'
set @domain = substring(@email, charindex('@', @email)+1, charindex('.', @email) - (charindex('@', @email) + 1))
print @domain
Chris
Ok, then drop the part to the right of the last dot:
declare
@email varchar(50),@domain
varchar(50)set
@email = 'johndoe@nl.eu.whatever.com'set
@domain = substring(@email, charindex('@', @email)+1, 50)set
@domain = substring(@domain, 1, len(@domain) - charindex('.', reverse(@domain)))
This gets the subdomains as well, if you only want the top domain you'll have to do sonthing similar to get the bit after the last dot.
Regards Gert-Jan
If you want to get fancy, you could try something like this:
http://blogs.msdn.com/sqlclr/archive/2005/06/29/regex.aspx
This 'should' handle just about any eMail address you can come up with.
DECLARE @eMail varchar(100)
SET @eMail = 'john.doe@nl.eu.whatever.com'
SELECT parsename( substring( @eMail, ( charindex( '@', @eMail )), len( @eMail )), 2 )
(This darn #$%#^* editor overrides our code formatting. No code above should be underlined -or blue for that matter!)