473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to extract an email from the FROM field

What i want to do is extract an email from the FROM field which is stored in the following format
"vini katyal" <vinikatyal@yahoo.com> varchar field
Oct 1 '11 #1
6 6192
patjones
931 Expert 512MB
I take it that you're looking to do this via a simple SELECT query?

Pat
Oct 3 '11 #2
ck9663
2,878 Expert 2GB
You need to parse that column. What do you have so far?



~~ CK
Oct 3 '11 #3
patjones
931 Expert 512MB
You could try something like this. It assumes that you have a table of digits (tblDigits) from 1 to 100, under a column name digit.

Expand|Select|Wrap|Line Numbers
  1. SELECT SUBSTRING(tblContacts.fldEmail, tA.digit + 1, tB.digit - tA.digit - 1)
  2. FROM tblContacts, tblDigits tA, tblDigits tB
  3. WHERE tblContacts.fldEmail IS NOT NULL
  4.       AND
  5.       tB.digit - tA.digit > 0
  6.       AND
  7.       tB.digit - tA.digit < LEN(tblContacts.fldEmail)
  8.       AND
  9.       SUBSTRING(tblContacts.fldEmail, tA.digit, 1) = '<'
  10.       AND
  11.       SUBSTRING(tblContacts.fldEmail, tB.digit, 1) = '>';

I'm sure there are other possibilities.

Pat
Oct 3 '11 #4
Expand|Select|Wrap|Line Numbers
  1. DECLARE @Email varchar(50)
  2. SET @Email = '"vini katyal" <vinikatyal@yahoo.com>'
  3. SELECT
  4. SUBSTRING(@Email,
  5. charindex('<',@Email),
  6. LEN(@Email)) as [email]
Oct 20 '11 #5
patjones
931 Expert 512MB
@clvandyke: Good stuff! I cut and pasted it into my SSMS window and it works nicely. It would be great if the OP can weigh in.

Pat
Oct 20 '11 #6
nbiswas
149 100+
Try this

Expand|Select|Wrap|Line Numbers
  1. Declare @str varchar(50) = '"vini katyal" <vinikatyal@yahoo.com>'
Solution 1
-------------

Expand|Select|Wrap|Line Numbers
  1. Select 
  2.         Name  = Left(@str, PATINDEX('%<%',@str)-1)
  3.         ,Domain = Right(@str,Len(@str)-PATINDEX('%<%',@str)+1)
  4.         ,Email = @str
  5.  
Solution 2
Expand|Select|Wrap|Line Numbers
  1. Select 
  2.         Name  = Left(@str, CHARINDEX('<',@str)-1)
  3.         ,Domain = Right(@str,Len(@str)-CHARINDEX('<',@str)+1)
  4.         ,Email = @str
  5.  
Solution 3
Expand|Select|Wrap|Line Numbers
  1. Select 
  2.         Name  = REVERSE(STUFF(REVERSE(@str),1,PATINDEX('%<%',REVERSE(@str)),''))
  3.         ,Domain = STUFF(@str,1,PATINDEX('%<%',@str)-1,'')
  4.         ,Email = @str
  5.  
Solution 4
Expand|Select|Wrap|Line Numbers
  1. Select 
  2.         Name  = SUBSTRING(@str,1,CHARINDEX('<',@str,1)-1)
  3.         ,Domain = Right(@str,Len(@str)-CHARINDEX('<',@str)+1)
  4.         ,Email = @str
  5.  
In all the four cases the result is as under

Expand|Select|Wrap|Line Numbers
  1. Name    Domain    Email
  2. "vini katyal"     <vinikatyal@yahoo.com>    "vini katyal" <vinikatyal@yahoo.com>
Hope it helps
Oct 23 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: jason | last post by:
Access 2000 I need some help interogatting a table and extracting via ASP the final field in a row which has a value. In other words, I have a maximum of 10 fields but, at the user level he may...
1
by: Adrian | last post by:
Hi, I would like to ask whether do anyone who where or how can i extract email address from Exchange Server or Microsoft Outlook from a Web Application Adrian
2
by: MLH | last post by:
I routinely save failure notices from mail servers bouncing mail back to me that I sent with invalid address. I would like to write an access procedure in my contacts database that would open the...
1
by: vjp2.at | last post by:
I get an email that says "Joe is a bozo, he has 333 baloons" I have user-defined Outlook fields for BOZO and BALLOONS. I want to have the program to automagically start a new record and put "joe"...
0
by: visu | last post by:
I ve a text paragraph something like sample sample sample sample rr@yahoo.com <ee@ss.comsample sample sample sample sample sample sample sample sample sample ds@example.com sample sample sample...
6
by: bcotten | last post by:
I have a simple Contact Management database. There is a table called 'Contacts' containing a email field. I need to concatenate each record's email field into one text string separated by a...
4
by: Alexander Vasilevsky | last post by:
How to extract email address from the letter in Outlook Express? http://www.alvas.net - Audio tools for C# and VB.Net developers
0
by: Alexander Vasilevsky | last post by:
How to extract email address from the address book in Outlook Express? http://www.alvas.net - Audio tools for C# and VB.Net developers
2
by: Alexander Vasilevsky | last post by:
I need extract email address from the address book in Outlook Express also. http://www.alvas.net - Audio tools for C# and VB.Net developers
1
by: Alexander Vasilevsky | last post by:
How extract email address from the address book in Outlook Express? http://www.alvas.net - Audio tools for C# and VB.Net developers
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.