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

Finding duplicates and returning them with related information in XML

The following query returns all orders with a given order number. How do I re-write it so that the specified duplicate order IDs are returned along with their respective custid and/or company name? DECLARE @x AS XML; SET @x = N'
SteelyDanFan
  • 79
  • 4
  • 12
0
votes
1 answer

How do I pull the value of an attribute from XML using XQUERY?

CREATE TABLE SportsEvent (ID INT, Name NVARCHAR(20), Results XML); GO DECLARE @Results XML= ' John Doe Harry Smith Kenneth Brown
SteelyDanFan
  • 79
  • 4
  • 12
0
votes
1 answer

How to check if one string is a substring of another and print it out if true (XQuery/XML)

In the below code, $y returns one attribute value that looks like "OK HL DJ FJJ FJ" etc. $l returns attribute values that look like "OK" "HL". The idea, is that I want to see if $l is contained within $y, and if so to print it out. So really the…
0
votes
0 answers

Script for multiple indexes using xquery

Hi I've been trying to get all the XML tags values, But I am having issues, for instance I am able to get all the tag values if I manually add the index as [1],[2],.... but I want all the tag values with all indices,
0
votes
1 answer

Check whether one of the attributes contains given value or not

I am using SQL Server 2012. I have the following code DECLARE @p varchar(4) SET @p = ext1 DECLARE @x xml SET @x = '
Sargis Koshkaryan
  • 1,012
  • 3
  • 9
  • 19
0
votes
1 answer

how to I add where clause or constraint to my xquery

I have been given a station in london - warren street station, euston, and i have to return the stations which have the same bike availability as warren street station and at least as many empty docs. I have written a small query to return warren…
Emma
  • 1
0
votes
1 answer

XQuery with SQLServer finding nodes with a wildcard

I have an XML document similar to below with multiple links stored in a SQLServer database Some URL I'm trying to extract all the Links using: select…
Eduardo
  • 6,900
  • 17
  • 77
  • 121
0
votes
1 answer

How to extract string in xml field using Oracle sql

I want to extract the error code from the xml string which is CLOB data type in my oracle table. But when i tried to extract it gives me an error as ORA-19114: XPST0003 - error during parsing the XQuery expression: LPX-00801: XQuery syntax error…
Andrew
  • 3,632
  • 24
  • 64
  • 113
0
votes
1 answer

Using XQuery to match existing records, and then delete said record if found?

I have an XML data source stored in a Temporary Table using XQuery, and have successfully inserted this into the database. My problem is that I don't know how to check if something exists first, and then delete it, base on the statement. Here's the…
user4099684
0
votes
1 answer

How to update records with multiple tables linked by a foreign key using XQuery (or OPENXML) in SQL Server?

I have T-SQL code like this: DECLARE @xml XML = (SELECT CONVERT(xml, BulkColumn, 2) FROM OPENROWSET(Bulk 'C:\test.xml', SINGLE_BLOB) [blah]) -- Data for Table 1 SELECT ES.value('id-number[1]', 'VARCHAR(8)') IDNumber, ES.value('name[1]',…
user4099684
0
votes
2 answers

Using xquery to select a node's inner xml as a string when it contains an html image tag

I have an xml field that I need to select the inner xml from a node as a string regardless of what the inner xml is (in this case, it's an html image tag). I'm able to get plain text with no problems but when I have something with the image tag in…
Ken
  • 342
  • 2
  • 5
0
votes
1 answer

Query Xml data in Sql Server holding serialized objects

We are storing some serialized objects in an Xml-column in Sql Server. I would like to create a query that gives me the list of serialized objects (rows) where a specific field has a specific value. My Xml looks like this:
Jesper Lund Stocholm
  • 1,973
  • 2
  • 27
  • 49
0
votes
1 answer

Get the xml below root level through XQuery

I have an XML as below stored in a table. ` Mark A Antomy
Clare Clarkson
` I…
Vaibhav Verma
  • 47
  • 2
  • 11
0
votes
1 answer

Modify xml column in Sql Server 2005 database using php 5.2 mssql_query

I have an xml column setup in a table on a SQL Server 2005 database and I am trying to add a node to the xml tree through php 5.2. The structure of the xml consist of a root node with name "YearsAttended" and child nodes with a name of "year".…
0
votes
1 answer

SQL Server Dynamic XQuery

I'm trying to pull data from XML (stored as NText) in a SQL Table. Suppose we have two tables, each with XML: | TABLE 1 | | TABLE 2 | |ID| NAME |FIELD_DEFINITION| |ID|DEF_ID|VALUES| |1 |FIELD 1|
Ahhhhbisto
  • 339
  • 3
  • 13