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

Sum using XQuery

I'm using XQuery to perform addition. Following is the structure of XML saved in database: 1 1001 50,1
Puru
  • 47
  • 2
  • 4
1
vote
2 answers

How to Extract data from xml column in sql 2008

I have a table with a column of type xml. I have to extract the values from the xml column. I have tried all possible ways and i couldn succeed.Please find below the sample of the xml data. 1
user1254494
  • 11
  • 1
  • 3
1
vote
2 answers

What the purpose of text() in this xquery

update tbl_xml set mov_vcds.modify('replace value of(/videos/video/title/text())[1] with "Anbu"') without text() can we use this query..
Anboo
  • 103
  • 2
  • 17
1
vote
1 answer

XML attributes query in Qexo.

I've the following XML, I used Xquerry to query some results using Qexo. How to query only the attributes like affiliation? Like if i want to query all affiliations of each author? I could do the simpler ones, but this is very tricky and din't get…
Abhilash Muthuraj
  • 2,008
  • 9
  • 34
  • 48
1
vote
1 answer

Insert xml element contents(which is also xml tags) into column in SQL Server 2005

For a table schema like below CREATE TABLE [dbo].[Employee]( [EmployeeId] [uniqueidentifier] NOT NULL, [Name] [nvarchar](50) NOT NULL, [Location] [nvarchar](50) NOT NULL, [Skills] [xml] NOT NULL, [Projects] [nvarchar](400) NULL, …
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178
1
vote
1 answer

SQL XQuery command to recursively get descendants of same type

I'm new to XQuery in SQL but I'm understanding the basics of getting nodes and the values of the queries. My issue now is handling a hierarchy of unknown depth. The relationship is Contract -> Project -> Lines; and looks something like…
Thelonias
  • 2,918
  • 3
  • 29
  • 63
1
vote
1 answer

SQL XQuery and Cross Apply problems...too many rows in results

I have a table of contracts. There are several columns and finally an XML column representing the whole contract. Inside the contract are projects (1 or more) and inside each project are 1 or more lines. I need to be able to select all of the…
Thelonias
  • 2,918
  • 3
  • 29
  • 63
1
vote
2 answers

Updating SQL Server XML node

I am trying to update a node Qty of my XML which is stored inside a SQL Server XML column, no error occurred but my field did not got updated. Please advice. Thanks. XML data copied from SQL Server xml column:
k80sg
  • 2,443
  • 11
  • 47
  • 84
1
vote
1 answer

Parse XML where data is pivoted

I have the following XML data ABC01 Company 1 …
xE99
  • 62
  • 7
1
vote
3 answers

Using T-SQL Xquery to extract data from XML with low-ascii represented like "&#x1E"? Or just use T-SQL?

I have strings inside XML that contain low-order ASCII. Specifically, the EDI contains special characters like char(28), char(29), char(30) (aka File Separator/Group Separator/Record Separator). The way the devs encode it in the XML string, these…
mbourgon
  • 1,286
  • 2
  • 17
  • 35
1
vote
1 answer

How do I display a guest's full name (family_name, given_name) from another table using only guest_id from the first table?

For my question I am to create a query showing the guest's full name that have made more than 2 bookings. It is to show the (family_name, given_name) in one column under the alias "Guest" AND alias "Count(*)" which what assume, counts the the…
1
vote
1 answer

xQuery - Returning MAX Row

I'm pulling what hair I have left out! The resultset is all good but I now need to do something else. Here's the T-SQL SELECT documentdate , x.a.value('(Date)[1]','varchar(50)') as [Date] , x.a.value('(ReadCode)[1]','varchar(50)') as…
pee2pee
  • 3,619
  • 7
  • 52
  • 133
1
vote
1 answer

Extract Date Value from child node

I am needing to extract a date from a nested xml and am running into the issue of no output. The date I am attempting to retrieve is for Field name="A". My expected output is 2022-04-12. Here is the sample data along with the query I have generated.…
Michael M
  • 11
  • 2
1
vote
2 answers

SQL Server XML Type Select Where Attribute = X From Any Tag

select * from tablename where CONVERT(xml, Sections).value('(/sections/section/@value)[1]', 'varchar(1)') = 'f' will properly retrieve a record with the following value in the Sections column:
Dzejms
  • 3,108
  • 2
  • 30
  • 40
1
vote
2 answers

Why do we use [1] behind an order by clause in xquery expressions?

SELECT xText.query (' let $planes := /planes/plane return { for $x in $planes where $x/year >= 1970 order by ($x/year)[1] return ($x/make, $x/model,$x/year ) } ') FROM planes In this code, what is the purpose of [1] in…