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

Query joining primary table with foreign table and the top 3 records as a html from a column of the foreign table

I have two Tables: Category & Articles Category Table: CID | CategoryName ----+-------------- 1 | AAA Catg 2 | BBB Catg 3 | CCC Catg 4 | DDD Catg 5 | EEE Catg 6 | FFF Catg Articles Table: AID | CID | ArticleTitle | ArticleURL …
Stupid Dream
  • 140
  • 1
  • 9
2
votes
3 answers

Transform XML data into Tabular format in T-SQL

I would like to know how I could transform XML hierarchical data into tabular format and join with other relational database tables in SQL Server 2005 T-SQL (XPath/XQuery). For instance,
Thurein
  • 2,536
  • 7
  • 34
  • 49
2
votes
2 answers

Get data from parent xml which has different child xml tags in SQL server

I have an xml whose parent tag have different child tags based on it modelType. All I want is to get those different child tags data in a single Select query. Here is the my xml
2
votes
2 answers

Which other teachers are teaching the courses that are being taught by John Cullen.SQL

I have multiple tables but for this query only need two tables those are Faculty and CourseSection. I have tried the following but failed.If someone can help. Select faculty.firstname,faculty.lastname,CourseSection.facid,courseID from…
W.Ali
  • 45
  • 7
2
votes
2 answers

Inserting a value that comes outside of XML while using xQuery in stored procedure in MS SQL Server

I am parsing an xml input, using xQuery which helps parse xml files in a stored procedure like here, and then insert them into a table. I am able to insert the values from XML correctly into the table. However, I want to insert a newly created UUID…
tubby
  • 2,074
  • 3
  • 33
  • 55
2
votes
1 answer

SQL Server: How to get the value of a XML element specifying an attribute?

For the usage in a SQL query I need to get the value of a specific XML element. The XML element is specified by its attribute. My XML elements looks like this: example
bert
  • 35
  • 1
  • 7
2
votes
1 answer

how to return element attribute value

Here's an example, I'm trying to return the value attribute value: IF OBJECT_ID(N'tempdb.dbo.#XMLwithOpenXML') IS NOT NULL DROP TABLE #XMLwithOpenXML; CREATE TABLE #XMLwithOpenXML ( [XMLData] [XML] NULL , [LoadedDateTime]…
sqlpadawan
  • 305
  • 1
  • 5
  • 15
2
votes
2 answers

Xquery SUM after value has been rounded

I want to sum the quantity of all products/Product/Quantity after the value has been rounded. My XML looks like: 116511 2.99 1.500 4.08…
2
votes
1 answer

SQL Server xquery sum cast error when schema data type is string

Trying to run this in SQL Server 2014 in order to sum all Values in "UserData" xml: IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'SC') DROP XML SCHEMA COLLECTION SC go CREATE XML SCHEMA COLLECTION SC AS N'
Jon
  • 23
  • 2
2
votes
2 answers

I would like to replace a element with a new xml element in a Open XML document using XQuery

Here is a sample of the XML document before I run my XQueries:
tstorli
  • 53
  • 3
2
votes
2 answers

How can I insert multiple xml nodes with XMLQuery (XQuery) in Oracle SQL?

I have created the following test case to demonstrate my issue: create table test_table (idx number, a varchar2(20), b varchar2(20)); insert into test_table values (1, 'item1', 'value1'); insert into test_table values (2, 'item2', 'value2'); select…
DBox
  • 49
  • 1
  • 7
2
votes
1 answer

How to use XQuery to fetch NULL values for INT

I have the following example DECLARE @MyXml XML SET @MyXml = CONVERT(XML, '
fahadash
  • 3,133
  • 1
  • 30
  • 59
2
votes
1 answer

Insert element into XML using XQuery in SQL Server

I need to insert a column in a stored procedure which reads XML as input and reads the XML value using XQuery in SQL Server. Consider a table dbo.emailDetails Create Table dbo.emailDetails ( EmailId int, HomeEmail varchar(250), ); XML…
salaiviswa
  • 43
  • 8
2
votes
2 answers

XQuery Comparison Expressions in SQL Column

I would like to have a table that I can store XQuery Comparison Expressions in, so that I can evaluate them in a query. I've been doing a bit of R&D into if it is possible, and I'm struggling. If I put an XQuery expression in a column, then it seems…
stormCloud
  • 983
  • 1
  • 9
  • 24
2
votes
2 answers

Read child node along with its parent attribute from XML in SQL server

I have an XML similar to this structure. a2bh5 abc ETL SSIS B
Jasqlg
  • 183
  • 1
  • 9