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

How can I write an XQuery accessing XML stored in separate SQL Server tables?

I have created a new database with two tables to test SQLServer 2008 XML functionality. If I will succeed in obtaining the desired behaviour I will have to create about 50 tables to then import lots of XML files for a new project. My test…
MarioCannistra
  • 275
  • 3
  • 12
3
votes
1 answer

Updating an attribute with xquery in sql server 2008 R2

I have a table that defines the layout of a form in XML. There are nodes inside of it that have attributes like Id (GUID), and DataType (char), etc... This XML data is used to create a form at run-time, when data is saved it's writen…
Nick
  • 4,556
  • 3
  • 29
  • 53
3
votes
2 answers

TSQL Removing tab and line feed from xml values

I'm trying to select a value from a xml column field with the following query: SELECT LTRIM(LocalData.value('(/root/questionphrase[@ln="nl"]/xhtml/p)[1]', 'nvarchar(max)')) FROM Question The structure of my xml:
Mark
  • 3,231
  • 3
  • 32
  • 57
3
votes
1 answer

Need a complex Xpath using sibling children, ancestors

I need to find attribute values based on other values pulled from parent's/grand-parent's sibling's children. I think it's going to take 2 different expressions. So given the following XML (which is derived from a log file that can be thousands of…
N1tr0
  • 485
  • 2
  • 6
  • 24
3
votes
2 answers

XQuery: Finding rows which contain specified xml data

I have a table which contains many rows, each with a column named "RecordData" that contains XML data that I wish to search upon. Three rows worth of example xml data from this column is given below: 1:
Sk93
  • 3,676
  • 3
  • 37
  • 67
3
votes
1 answer

Test for a specific node value in an XML column including potentially empty nodes

I have an XML column in a SQL Server 2008 database with values like the following simplified examples: Case 1 sometimes text here Case 2
Rick Riensche
  • 1,050
  • 1
  • 12
  • 25
3
votes
1 answer

How to decode & etc using XQuery/SQL?

Using Microsoft SQL Server... declare @x xml set @x = '<You & Me>' select cast(@x.query('/Example/text()') as nvarchar(50)) The result is "<You & Me>" rather than "". How can I have SQL read the XML…
billpg
  • 3,195
  • 3
  • 30
  • 57
3
votes
2 answers

How to print "<" and ">" using XQuery?

For example I am creating an element with dynamic data - XQUERY let $sttag:= concat('<', '/') return concat ($sttag, "newTag") above XQuery returns output as </newTag instead of " using xquery?
dwarkesh
  • 1,378
  • 2
  • 10
  • 12
2
votes
2 answers

How to read data from an XML variable?

I've an xml variable with the below given format, and I do need to dinamically read and load into some T-SQL structure the element names and its respective fields values: declare @InputXml xml Set @InputXml = '
G21
  • 1,297
  • 2
  • 18
  • 39
2
votes
1 answer

How to retrieve value of attribute in xml datatype based on parameter name in SQL Server 2008 R2?

I have the following sample xml in a column of xml data type: I want to have a stored proc where I am able…
Teto
  • 800
  • 6
  • 15
2
votes
2 answers

Extract data from xml

i came to know that the below sql can be used to extract data from xml --XML DATA SAMPLE DECLARE @xmlvar xml SET @xmlvar=' JID
Thomas
  • 33,544
  • 126
  • 357
  • 626
2
votes
1 answer

Fixing SQL Update using XQuery modify to work on SQL 2005

I'm trying to move a bunch of fields from a table into an xml blob contained within the same table. After this is successful I will be removing the column from the table. A really simple version (without the drop column) of what I've come up with is…
Tr1stan
  • 2,755
  • 1
  • 26
  • 45
2
votes
1 answer

Transform XML to Table data using XQuery in SQL Server

Is it possible to achieve the following table from of output using XQuery in SQL Server Edit: A change in my requirement, Consider i have a table which stores the below xml and also UserID DECLARE @XML xml set @XML = '
Sandeep Polavarapu
  • 382
  • 1
  • 6
  • 25
2
votes
1 answer

Equivalent to AS in XQuery?

Is there anyway in xquery to do like in sql: "SELECT name AS buyer"? enter code here let $stars := doc("stars.xml") for $s in $stars/Stars/star where $s/Address/Street eq "123 Maple St." return $s/(Name **AS buyer** |cost) output something…
ZedORYasuo
  • 183
  • 7
2
votes
1 answer

Implement an IN Query using XQuery in MSSQLServer 2005

I'm trying to query an xml column using an IN expression. I have not found a native XQuery way of doing such a query so I have tried two work-arounds: Implement the IN query as a concatenation of ORs like this: WHERE…
Mario
  • 183
  • 2
  • 6