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
1 answer

xQuery delete nodes based on list of values for single attribute

Let's say we have this simple XML structure:
Mincho Minchev
  • 222
  • 3
  • 13
2
votes
3 answers

XQuery with dynamic XPath from XML Sql Server Column

I have a log table has xml column which contains log contents There is also table called logType which is the type of log I need to create query descripes the xml contents as readable string I added a column with name logXPath to logtype table and i…
user897645
  • 85
  • 2
  • 8
2
votes
1 answer

SQL Server 2014 - XQuery - get comma-separated List

I have a database table in SQL Server 2014 with only an ID column (int) and a column xmldata of type XML. This xmldata column contains for example: a nice Novel Maria
billdoor
  • 1,999
  • 4
  • 28
  • 54
2
votes
1 answer

SQL Server XQuery to select record if XML Column contains element with value

I want to select the records from the Orders table. It contains the OrderXML as XML type column. if OrderXML has order with status given by user then it should select the record. I am trying following query but not working - SELECT * FROM ORDER…
Bhalchandra K
  • 2,631
  • 3
  • 31
  • 43
2
votes
1 answer

How to retrieve attribute only using xQuery

I have a function similiar to the following, returning large chunk of xml (in production environment), In various stages of the application , we need to retrieve only some of the elements or only some attributes from this. create function…
TonyP
  • 5,655
  • 13
  • 60
  • 94
2
votes
1 answer

How to read data from XML that is stored as image type in SQL?

I have an XML stored in the SQL as image type. What I'm trying to and actually managed to accomplish is to get a data from that stored xml. The problem is the data is stored as unicode, but what I'm getting is an ascii type of the data. I've tried…
2
votes
1 answer

add a node to xml column in select query

I would like to add a node with a value from a table column. my example is below declare @table table (bookid int,xmlCol xml) insert into @table select 1, '
user829982
  • 121
  • 1
  • 2
  • 8
2
votes
1 answer

Parsing XML with namespaces in SQL Server

I am having a hard time trying to parse an XML that has some namespaces defined:
2
votes
1 answer

How can I shred xml and retain the associations?

I have the following xml. If you run it, you will have 3 grid results. I am struggling with the last grid results as I need that grid results to have the relevant associations. In other words, I would like to have the relevant RowID from Grid…
Daisy
  • 167
  • 1
  • 2
  • 11
2
votes
1 answer

xquery replacing value if node exist

I'm working with xQuery and I'm trying to replace the value of test element if the element tag Active does not exist under the User element. (I added quotes to be able to display it here properly...) declare @testXML xml = ' 10
user2355293
  • 55
  • 1
  • 7
2
votes
1 answer

select multiple nodes xml

I'm retrieving xml formatted text from ntext fields (sample format of a row below): Some Company http://www.someurl.com Benefits…
lance-p
  • 1,050
  • 1
  • 14
  • 28
2
votes
4 answers

Questions About Sort Order Using XQuery in SQL Server

Is the result of a SELECT like the one below using XQuery in SQL Server guaranteed to be in document order, that is in the original order the nodes are listed in the xml string? DECLARE @x XML = '' SELECT…
user12861
  • 2,358
  • 4
  • 23
  • 41
2
votes
1 answer

xquery return Boolean if node exists at a certain location or not

I have XML similar to the following in a SQL 2008 database, stored in an XML field. I would like to return a true or false indication if a node exists in a specific section of the XML.
N1tr0
  • 485
  • 2
  • 6
  • 24
2
votes
2 answers

Efficient way of doing "insert only if node with specific value does not exist" for an xml column

Say, I have a xml column that looks like this: 42 Assuming table: Word(WordId:bigint, Wordtext:nvarchar, MessageIndex:xml) I do NOT want the following parameterized query to insert a new xml node if @MessageId already exists…
Yuriy Gettya
  • 693
  • 10
  • 20
2
votes
1 answer

XML Column - Cannot atomize/apply data() on expression that contains type 'xxx' within inferred type

Introduction I'm trying to query an xml column in SQL server 2008, but I get an error I can't fix. This is the schema I use: CREATE XML SCHEMA COLLECTION PublicationSchema AS '
user369117
  • 775
  • 1
  • 8
  • 19