xquery-sql

Pivot XML using XQuery and filter on attribute

Given the following XML (in an SQL column field called 'xfield'): <data> <section> <item id="A"> <number>987</number> </item> <item id="B"> <number>654</number> </item> <item id="C"> <number>321</number> </item> </section> <section> <item id="A"> <number>123</number> </item> ...

XPath/XQuery: Select a root node with its attributes without childs

I have an xml: <Customer id=""> <Name /> <Address /> </Customer> I would like to select ONLY a root node with its attributes without its child nodes: <Customer id=""/ > Is such thing possible with XPath? ...

XQuary adding or replacing attribute in single SQL update command

I have a Table with an XML column, I want to update the xml to insert attribute or to change the attribute value if the attribute already exists. Let's say the starting xml is: < d /> Inserting: UPDATE Table set XmlCol.modify('insert attribute att {"1"} into /d[1]') Changing: UPDATE Table set XmlCol.modify('replace value of /d[1]/...

Comparison operations on xs:boolean in SQL Server 2005

Can anyone explain to me the results of this query: declare @xml xml; set @xml = '<node attribute="true">Val</node>'; select T.c.query('xs:boolean(@attribute[1])') Value, T.c.query('xs:boolean(@attribute[1]) = false') ValueEqualsFalse, T.c.query('xs:boolean(@attribute[1]) = true') ValueEqualsTrue, T.c.query('xs:boolean(...

What is the best way to generate dynamic advanced search queries that filter into xml columns in C#/TSQL

In our current set up we store client-specific data inside of an xml column in Sql Server instead of either creating client-specific columns or tables. This works fine except that it means we end up needing to use dynamic sql for queries that query into those values, passing into our sprocs a partial where clause generated in code. W...

Manipulating the xml column in sql server using Xquery.

Hi All, I am storing an xml file in the xml datatype in table of SQL Server. Now I want to fetch some fragments (using xquery) and then update the fragments with the modified fragments (using xquery). I need some suggestions. I have the code to delete a node and it is as below but while deleting I need to insert the modified node at th...

Using a variable in a SQL Server 2005 stored procedure with XQuery

I'm working with the following XML <AEDControl ControlGU="17fed98c-8128-4c6b-9b50-3dbe73889b9d" ControlLabel="Posting Status" TypeGU="6b4d08b1-6340-450c-beae-517b7d84e717" ControlDescription=""> <Elements> <Element ElementGU="2da346d1-2e05-4aa3-9bae-5aa9b3b75d5c" Label="Active" ...