Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

extract email address from the string

I have the string from the MS exchange server which lists the email address. However, the email address list like this John Smith <john.smith@test.com>.. I need to get just the email john.smith@test.com in sql 
Avatar of HainKurt
HainKurt
Flag of Canada image

use

replace(replace(email,'<',''),'>','')

Open in new window

if it has name

declare @email varchar(100) = 'John Smith <john.smith@test.com>'

select substring(@email, charindex('<',@email)+1, charindex('>',@email)-charindex('<',@email)-1)

john.smith@test.com 

Open in new window


Avatar of erikTsomik

ASKER

what if it is combination so in one record has a name and the other record has not name like this 111111111@txt.att.net
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome