Ask questions via twitter! Message any question to @answers on twitter. We'll publish the question and send you a reply each time there's a new answer.
Next Question

Answered Question

 
M$1 December 31, 2008 04:43 PM

In MS SQL 2005, is there a way to determine whether a specific node exists in an XML variable?

For example, say I have the following XML:

.... [parentNode]

........ [test1][/test1]
........ [test2][/test2]

........ [subNode]
............ [subTest1]123[/subTest1]
............ [subTest2]234[/subTest2]
........ [/subNode]

.... [/parentNode]

Once I load the XML into a variable, there will be instances when [subNode] may or may not exist. What's a straightforward method to detect whether [subNode] is present?
Interesting Question?  Yes (0)   No (0)   
RSS
 
 

Best Answer  Chosen by Asker

 
January 01, 2009 07:23 AM
Wait, I thought you were doing it in 2000? Anyway, something like this:

RETURN (SELECT @xmlData.exist('/parentNode/subNode'))

you might have to mess with the xpath query a little depending on the exact structure but I am pretty sure something like that will work.
Source(s):
http://msdn.microsoft.com/en-us/library/ms345117.aspx (under heading Example: Constraining XML Column)

Asker's Rating:


Helpful Answer?  (0)   (0)    Tip ilaksh for this answer
Permalink | Report
   Reply  
 
 
 
January 01, 2009 07:37 AM
Thanks; this issue actually I can use the features of 2005 with. The one related to the other question I can't because of time constraints; the time it'd take to change all the underlying code to use 2005's better XML functionality will have to wait until a deadline of mine has passed.

Report
 
 

Other Answers (1)

Sort By
 
December 31, 2008 06:08 PM
It appears that SQL supports XML queries, but I would do this type of query on the application level. Here's an interesting article on SQL and XML:

http://www.15seconds.com/Issue/050803.htm

Helpful Answer?  (1)   (0)    Tip dotnetallday for this answer
Permalink | Report
   Reply  
 
 

Answer this Question

How tips and payments work

This question has already been resolved. You may add an answer to it but you will not be eligible to win best answer or any associated tips.

Ask a Question


140 characters left
Top of Page
Buy Mahalo Dollars with Credit Card or PayPal

Top Members

This Week All Time
  • cfinke
    cfinke
    2nd Degree Black Belt
    27330 Points
    M$29.75 Earned
  • bunnyphuph...
    bunnyphuph...
    2nd Degree Black Belt
    21386 Points
    M$762.89 Earned
  • opher
    opher
    Purple Belt with a Brown Tip
    6142 Points
    M$238.49 Earned
   See All
 

Most Popular Tags

mahalo(1800)
music(495)
iphone(485)
google(392)
online(369)
food(340)
beer(287)
money(284)
movies(281)
apple(259)
aotd(235)
free(233)
health(228)
video(224)
dog(217)
   See All
 

Categories

Welcome New Members


 
 
Mahalo Dollars are the currency of Mahalo Answers.

Each Mahalo Dollar costs $1.

Once you earn more than 40 Mahalo Dollars, you can request to be paid via PayPal. Each Mahalo Dollar is currently worth $0.75 when paid out via PayPal. Learn More

 
 

Please log in to use this function.