473,386 Members | 1,773 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,386 software developers and data experts.

Extract email address embedded in a xml string using a select query in SQL

I have a table in SQL with the following columns and data:

First_name is Joe
Last_Name is Smith
Zipcode is 12345
Join_date is 05012011
xmldata is
Expand|Select|Wrap|Line Numbers
  1. <data>Network Admin</data>
  2.     <definition_field_id>beaa46b0-d1bb-408a-a5cc-56764f8562b6</definition_field_id>
  3.     <validation_status>Valid</validation_status>
  4.  
  5. <field>
  6.     <data>Idontknow_noidea@noemail.net</data> 
  7.     <definition_field_id>a1cf1da8-7924-428b-b6b2-4315402738d9</definition_field_id>
  8.     <validation_status>Valid</validation_status>

How do I write a select query in SQL that will extract the email in a SQL query so my results can look like:

Joe, Smith, 12345, 05012011, Idontknow_noidea@noemail.net for the First_name, Last_Name, Zipcode, Join_date and email headers respectively?

Thanks
Jul 24 '12 #1

✓ answered by ck9663

Use PATINDEX to locate the start of <data> then use it again to local </data>. Using those numbers, you can use substring to get the string inside the data tags. No need to reverse.

Happy Coding!!!


~~ CK

3 2896
ck9663
2,878 Expert 2GB
If you need the XML for something else, I suggest you create a function that can parse it and return your desired element. If you don't need it for anything else, convert it to varchar(max) and look for the email tag, then just use substring to get the email address.

Happy Coding!!!


~~ CK
Jul 24 '12 #2
HI CK,I tried this but it doen't give me the whole email, cuts out the domain

Select top2
reverse(substring(reverse(substring(cast(xmldata as varchar(Max)),0,charindex('@',cast(xmldata as varchar(Max)))+len('<data>'))),0,
patindex('%>%',reverse(substring(cast(xmldata as varchar(Max)),0,charindex('@',cast(xmldata as varchar(Max)))+len('.')))))) as email_id
from mytable

Where am I going wrong?
Jul 24 '12 #3
ck9663
2,878 Expert 2GB
Use PATINDEX to locate the start of <data> then use it again to local </data>. Using those numbers, you can use substring to get the string inside the data tags. No need to reverse.

Happy Coding!!!


~~ CK
Jul 24 '12 #4

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

Similar topics

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
1
by: asenthil | last post by:
Hai, Can any one tell me, How to retrive rows in alphabetcal order in the mysql database by using select query? thanks.. senthil
4
by: Ciaran | last post by:
Hi can someone give me hand with this please? What's the best way to extract the extension from the url? example: $string="http://www.domain.co.uk/anypage.html" In this example, I'd be...
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
30
by: iheartvba | last post by:
Hi, I already have 3 Databases running: A. they all have the same tables and the same structure B. There is no 1 Master table they are all separate tables What I want to do is to merge them...
3
Ashwani Sharma
by: Ashwani Sharma | last post by:
Is there any simple way to validate email address without using regular expressions?? Thanks in advance, Ashwani Sharma
3
by: Peggy Frazier | last post by:
I am using Microsoft Access 2010 and attempting to use a query to pull select data from a linked database. The link is via ODBC. My connection with the database is fine, I have successfully...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.