Questions tagged [xquery-sql]

the XQuery language as supported by database systems. Include the tag of your system to specify ("sql-server", "oracle", "postgresql", etcetera). Use the "xquery" tag on its own for general questions about XQuery.

XQuery is a query language designed to extract data from arbitrary XML documents. Multiple RDBMSes support XQuery as part of the SQL/XML standard or using proprietary syntax. What follows is a non-exhaustive list.

Microsoft SQL Server

In SQL Server 2005 and onwards, the xml data type methods, in particular .query(), support querying XML and returning the results as relational data. These methods support a subset of XQuery, with special support for some T-SQL specific constructs like variables -- see the XQuery Language Reference for specifics.

Oracle

Oracle includes XML support as Oracle XML DB. It supports XQuery both for querying and updating data, both relational and XML. The XMLQUERY function is used to issue XQuery queries within an SQL statement.

453 questions
26
votes
3 answers

How do I select a top-level attribute of an XML column in SQL Server?

I have an XML column in SQL Server that is the equivalent of: I want to get the value of the foo attribute of Test (the root element) as a varchar. My goal would be something along the lines…
Alex Argo
  • 8,920
  • 12
  • 43
  • 46
22
votes
1 answer

selecting individual xml node using SQL

I have a large XML note with many nodes. is there a way that I can select only a single node and all of its contents from the larger XML? i am using sql 2005
kacalapy
  • 9,806
  • 20
  • 74
  • 119
10
votes
1 answer

Sql Xquery How to Replace text in Update Query

Table is named as MasterTable Columns ID type BIGINT, Name type VARCHAR(200) (stores xml type data for some reasons) Name contains data structured as SomeEnglishTextSomeItalicText When I need to Update the Master Table…
Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
9
votes
1 answer

Update substring in XML column SQL Server 2008

I want to perform an update on all the rows in an XML column in SQL Server 2008, replacing just a substring in a certain xml node. I'm new to XML DML / XQuery and all that and I just cannot figure out how to do it. Example of XML in the column I…
Kberg
  • 161
  • 1
  • 2
  • 8
9
votes
3 answers

Compare two sets of XML data using XQuery in SQL Server

Suppose I store employee data in a xml column in my log table. Sometimes data is also updated in the xml column from a stored procedure. Here is the sample example DECLARE @XML1 XML DECLARE @XML2 XML SET @XML1 = '
Thomas
  • 33,544
  • 126
  • 357
  • 626
8
votes
2 answers

Learning XQuery() in SQL server

SQL server 2008 sp2 I am a beginner and finding that XQuery syntax especially XPath very challenging. For e.g. trying to use various xml methods like exists(), nodes(), value() etc…. Is there a good tutorial online or book you recommnded?
cshah
  • 325
  • 1
  • 4
  • 13
8
votes
1 answer

Add node to XML using TRANSACT-SQL

I've been struggling with this simple piece of code without result. I'm just trying to add a new node to an XML variable. DECLARE @XML XML; SET @XML = ' 76
Oscar
  • 13,594
  • 8
  • 47
  • 75
8
votes
3 answers

Using SQL to transpose/flatten XML structure to columns

I am using SQL Server (2008/2012) and I know there are similar answers from lots of searching, however I can't seem to find the appropriate example/pointers for my case. I have an XML column in a SQL Server table holding this data:
Dav.id
  • 2,757
  • 3
  • 45
  • 57
6
votes
2 answers

XQUERY - How to use the sql:variable in 'value()' function?

The query below is trying to select a child node of a given Node. How do I use a variable instead of hard coding the child node such that I can pass them as parameters in a SProc? declare @T table(XMLCol xml) insert into @T values ('
Angshuman Agarwal
  • 4,796
  • 7
  • 41
  • 89
6
votes
4 answers

Update XML field with no text in T-SQL

I've come across a problem in updating an SQL field in that what I've written works perfectly for xml nodes with a text present, however it trips up when the node is empty. TEST
wonea
  • 4,783
  • 17
  • 86
  • 139
6
votes
2 answers

Which is faster .exist or .value in a where clause?

I am doing some crude benchmarks with the xml datatype of SQL Server 2008. I've seen many places where .exist is used in where clauses. I recently compared two queries though and got odd results. select count(testxmlrid) from testxml where…
Earlz
  • 62,085
  • 98
  • 303
  • 499
6
votes
4 answers

How to get list of document uri names from a database marklogic?

Hey I am trying to get the list of all document names /uri from a given MarkLogic database. I found this line in stackoverflow: How to get total number of documents in Marklogic database? ...which will get the count of documents in a database. I'm…
happybayes
  • 321
  • 4
  • 12
6
votes
2 answers

FLWOR in Sql server count number of hits

I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in…
FrenkyB
  • 6,625
  • 14
  • 67
  • 114
6
votes
1 answer

How to get value from XML attribute using Sql:Variable in xquery

I want to get attribute value from XML using Xquery. MY XML is 155 Product Below is my…
Mohmedsadiq
  • 133
  • 1
  • 10
5
votes
4 answers

Sort all attributes of XML in SQL query using XQuery

How can get the XML with sorted attributes using XQuery in SQL? for example for this XML: must return:
ARZ
  • 2,461
  • 3
  • 34
  • 56
1
2 3
30 31