?
Solved

SQL 2005 Xpath query help needed

Posted on 2009-07-08
2
Medium Priority
?
468 Views
Last Modified: 2013-11-11
Hi experts,

I need some help with making a query with a SQL 2005 XML column.

I have a table called EventLog, and this table has a column Details that is of type XML and contains details about an event log entry. Different event log entries may have different details. The XML for some of the entries looks like this:

(simplified)

<EventDetails>
  <item>
    <key>
      <string>UserID</string>
    </key>
    <value>
      <string>1</string>
    </value>
  </item>
  <item>
    <key>
      <string>InvoiceID</string>
    </key>
    <value>
      <string>13</string>
    </value>
  </item>
</EventDetails>

This one has two elements, UserID and InvoiceID, and their respective values.

What I need to do is to write a SQL query that will return * FROM EventLog WHERE the Details column has a InvoiceID element and its value is N (e.g. 123). This way I can find all event log entries that are somehow related to invoice 123.

Thanks in advance!
0
Comment
Question by:kerzner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Author Comment

by:kerzner
ID: 24857981
OK, nobody here can write that xpath query!?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 24875253
SELECT      *
FROM      EventLog
WHERE      Details.exist('/EventDetails/item/key[string="InvoiceID"]') = 1
      AND Details.exist('/EventDetails/item[value="13"]') = 1
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question