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
2
votes
3 answers

Xquery Get Consecutive Distinct Values

Trying to get consecutive distinct from the following XML. AB AB AB AC AB Expected Result : AB AC AB Current Result : AB AC Code : SELECT * ,STUFF(( TheParts.query(' for $x in…
raider
  • 93
  • 4
2
votes
2 answers

What type is returned from nodes() in a SQL Server XML query

If I have a SQL variable of the XML type, it's possible to use it directly as a column of the SELECT clause (even if the value is an XML fragment without a single root element) DECLARE @Items XML SET @Items =…
Jono
  • 1,964
  • 4
  • 18
  • 35
2
votes
1 answer

MSSQL 2008 get all levels of item

say I have xml in a SQL xml type field e.g. @x=' ' How would I go about getting nth level items in…
Shannow
  • 199
  • 3
  • 10
2
votes
2 answers

How to connect the values of peer nodes in t-sql

declare @x as xml =' hello world A0001 A0002 A0003 A0004 ' select xroot.value('(n1)[1]', 'varchar(255)') as n1, xroot.query('n2/text()') as n2 from…
Brucelin Michael
  • 475
  • 4
  • 10
2
votes
3 answers

Concatenate specific attribute of all elements together with xquery

How can I concatenate a specific attribute of all elements together using SQL XQuery? I have a table like this: InvoiceId Details --------- ----------------------------------------------------------------- 1001
ARZ
  • 2,461
  • 3
  • 34
  • 56
2
votes
1 answer

SQL Query + Google Geocode Response XML

I have the XML response from the Google Geocoding API stored in a SQL Server XML column. Can someone help me with a query that will return all rows where the XML contains > 1 result? e.g. OK
Dave Ziegler
  • 1,737
  • 3
  • 19
  • 36
2
votes
1 answer

Get all the Subchild values using XQUERY-SQL

I'm attempting to create an xquery expression that will return all the subchild node values. Now I get only the first subchild under each child. I have the following XML:
Gauranga
  • 127
  • 6
2
votes
2 answers

Concat XML nodes using XQuery

I required the following output Thomas Mapother Tom Cruise using the below XML using XQuery FLOWR Expressions. INSERT INTO XMLO1 VALUES (' Thomas
Harsha W
  • 3,162
  • 5
  • 43
  • 77
2
votes
1 answer

XQuery when a node doesn't exist

In the following XQuery syntax, I've added in the last table with a CROSS APPLY, and it seems to filter out some records. It would seem that this is the case because the node defined is optional. I thought that my code would result in the…
Chris
  • 21
  • 2
2
votes
1 answer

Sum XML Value based on different attribute types

I'm trying to extract number of adults, children and infants from the below example XML: Adults = AgeType 3 Children = AgeType 2 Infants = AgeType 1 and then count specifies how many of that age type. Correct result is: 35 Adults 5 Children 2…
DC07
  • 293
  • 5
  • 18
2
votes
2 answers

Update xml specific nodes in table based on joining values in xml field with T-SQL

I must gave this problem a lot of time and searching. I even almost get the output, but the problem is the one to many join that is causing my problem. here is my data --notice some of the Account nodes have elements that others don't DECLARE @tbl…
2
votes
3 answers

Return all possible values from xQuery

I have the below code which returns repair costs if I manually select the specific instances e.g.[1],[2] etc. I wanted to know if it was possible to return all items dynamically select * …
Krishn
  • 813
  • 3
  • 14
  • 28
2
votes
1 answer

Performance issue Flattening XML in SQL using Nodes, value methods and cross apply

I am trying to flatten the XML into SQL table using below code. The input datatable (@incomingTable) contains 10k un typed XMLs the query takes 7 sec to return the output. When I checked the Execution Plan found most of the time is spent on "Table…
user1745679
  • 209
  • 1
  • 2
  • 9
2
votes
1 answer

How to write an inquiry flwor xquery?

I have 5 cars, each car with 5 owners, I need to return those owners whose nation does not appear in the owners of other cars (can appear in the owners of the same car): 1 George Smith
Leon
  • 23
  • 2
2
votes
2 answers

Trying to list declared XML-namespaces

We have a number of applications accessing our APIs by providing XML data. At a certain point we decided to use xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" for incoming NULL-values to be able to distinguish empty values from…
TheConstructor
  • 4,285
  • 1
  • 31
  • 52