Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

IN clause for xml datatype Expand / Collapse
Author
Message
Posted Monday, January 21, 2013 11:51 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 10:22 PM
Points: 186, Visits: 957
I have xml something like below in my sql server table

<z>
<a>
<b>1</b>
<c>2</c>
</a>
<a>
<b>4</b>
<c>5</c>
.
.
.
so many tags similar to above
.
.
</a>
</z>
I wanted to remove some particular <a> node and it's child node where <b> has element 1,15,20..etc.

So to do this i have to do manually delete which is not efficient.So i was thinking of using IN command of sql so that i can specify values of <b> which has to checked inside IN command.

So how can i do it?

thank you
Post #1409807
Posted Tuesday, January 22, 2013 3:49 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 10:22 PM
Points: 186, Visits: 957
Anyone please reply me
Post #1409903
Posted Wednesday, January 23, 2013 10:13 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Yesterday @ 4:03 PM
Points: 727, Visits: 1,379
winmansoft (1/21/2013)
I have xml something like below in my sql server table

<z>
<a>
<b>1</b>
<c>2</c>
</a>
<a>
<b>4</b>
<c>5</c>
.
.
.
so many tags similar to above
.
.
</a>
</z>
I wanted to remove some particular <a> node and it's child node where <b> has element 1,15,20..etc.

So to do this i have to do manually delete which is not efficient.So i was thinking of using IN command of sql so that i can specify values of <b> which has to checked inside IN command.

So how can i do it?

thank you


I think you misunderstand the IN operator. The IN operator in T-SQL is used in WHERE clauses to test a value against a subquery or list of values and returns TRUE when the test value is equal to one of the values returned by the subquery or in the list. Comparison/logical operators cannot be used with the XML datatype.

If you want to find and replace nodes in XML within SQL Server, you'll need to put the XML documents or fragments in an XML datatype column and use XQuery: http://msdn.microsoft.com/en-us/library/ms345122(v=sql.90).aspx.
Post #1410698
Posted Wednesday, January 23, 2013 2:32 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, May 15, 2013 9:20 AM
Points: 76, Visits: 436
Try here: http://beyondrelational.com/modules/2/blogs/28/posts/10298/xquery-lab-17-how-to-update-the-value-of-an-element.aspx
If this is not exaclty what you need, there are lots of other examples of manipulating XML as well on this site.



Post #1410798
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse