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
Solved

SQL 2005 Xpath query help needed

Posted on 2009-07-08
2
464 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
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 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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