Unix Technical Forum

SQL 2005 XML Searching

This is a discussion on SQL 2005 XML Searching within the SQL Server forums, part of the Microsoft SQL Server category; --> hi i have a table with an XML column this XML data looks like this <details><attribute id="1" value="x"/><attribute id="2" ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 05:08 PM
zzzxtreme@gmail.com
 
Posts: n/a
Default SQL 2005 XML Searching

hi i have a table with an XML column

this XML data looks like this

<details><attribute id="1" value="x"/><attribute id="2" value="y"/
><attribute id="3" value="z"/></details>



could anyone help guide me on how to search something like this?

-------
Select * from Table Where (XMLColumn contains attribute of id="2" and
value like "y%")
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 05:08 PM
Plamen Ratchev
 
Posts: n/a
Default Re: SQL 2005 XML Searching

Here is one way:

SELECT keycol, datacol
FROM Foo
WHERE datacol.exist('/details/attribute[@id = "2"]') = 1
AND datacol.exist('/details/attribute[substring(@value, 1, 1) = "y"]') =
1;

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com