Solved

SQL 2005 Xpath query help needed

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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 …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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