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
 Extarcting EmailAddress

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2012-06-18 : 11:09:23
Dear All,

I need to extract all the emailaddress from 'comment' field in customer table

for ex:

Comment
sampltextsam[mailto:myname@aol.com]pltextsampltextsampltextsaampltexts
sampltextsampltextsampltextsampltextsaamplt[mailto:testname@gmail.com]
output
myname@aol.com
testname@gmail.com

Email address is hidden in this string field.I Need to find and extract.
Any help regarding this will be highly appreciated!

Thanks

Regards,
SG

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-18 : 11:57:55
if the format is consistent as shown above you can use logic like'


SELECT STUFF(STUFF(Comment,1,PATINDEX('%[mailto:',Comment)+8,''),CHARINDEX(']',Comment),LEN(Comment),'') AS emailaddress FROM Table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-06-20 : 07:29:11
or

select substring(comment,1,charindex('.com',comment)+3) from
(
select substring(comment,charindex('mailto:',comment)+8,len(comment)) as comment from table
) as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -