SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 test if xml node exists
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

olibara
Yak Posting Veteran

89 Posts

Posted - 04/08/2013 :  04:25:27  Show Profile  Reply with Quote

Hello

I have get ifo from XML fiels in a Database (horror IMO)

So to get the name of a seller I use the following select :

Select
Basket.ExtraInfo.value('(//Plugin[@name=''ClientAVendorInfoPlugin'']//Property[@key=''Name''])[1]','nvarchar(200)') AS 'Seller'
From Ventes


Unfortunately in some case the node have a different name

Select
Basket.ExtraInfo.value('(//Plugin[@name=''ClientABCVendorInfoPlugin'']//Property[@key=''Name''])[1]','nvarchar(200)') AS 'Seller'
From Ventes


I would like to make a CASE to test the existence of one or other node
But I'm not an XML select expert to get the syntax for that

Thanks for your help

Merci de votre aide

James K
Flowing Fount of Yak Knowledge

3719 Posts

Posted - 04/08/2013 :  09:12:04  Show Profile  Reply with Quote
Wouldn't using OR do the same thing?
Select
Basket.ExtraInfo.value('(//Plugin[@name=''ClientAVendorInfoPlugin'' or 
	[@name=''ClientABCVendorInfoPlugin'']//Property[@key=''Name''])[1]','nvarchar(200)') AS 'Seller'
From Ventes
Go to Top of Page

rama108
Posting Yak Master

109 Posts

Posted - 10/22/2013 :  10:38:15  Show Profile  Reply with Quote
I need to know if the xml node record exists in table.

SELECT col1,Col2 from tblA
WHERE @xml.exist('(/List/Element[@ID = col1 and @ID2 = col2

how do i construct this?

Thank you.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3719 Posts

Posted - 10/22/2013 :  11:59:49  Show Profile  Reply with Quote
Like this:
WHERE @xml.exist('/List/Element[@ID = sql:variable("col1")][@ID2 = sql:variable("col2")]') = 1

When you want to ask a question, it is better to start a new thread than append to an existing old thread.
Go to Top of Page

rama108
Posting Yak Master

109 Posts

Posted - 10/22/2013 :  12:33:54  Show Profile  Reply with Quote
Thank you James for your time, that works perfectly.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3719 Posts

Posted - 10/22/2013 :  13:04:34  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000