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
4
votes
4 answers

XPath/XQuery: Select a root node with its attributes without childs

I have an xml:
I would like to select ONLY a root node with its attributes without its child nodes: Is such thing possible with XPath?
Timofey
  • 2,478
  • 3
  • 37
  • 53
4
votes
1 answer

SQL Server XML XQuery select where clause attribute

I have a table with the following content Id | Guid | XmlDefinitionId 1 | 5a0bfc84-13ec-4497-93e0-655e57d4b482 | 1 2 | e28e786b-0856-40b6-8189-0fbd68aa3e45 | 1 And in another table the following XML structure…
mrtentje
  • 1,402
  • 2
  • 22
  • 43
4
votes
2 answers

What is the significance of [1] in Xquery

I am new to xquery in SQL Server. I have often come across xquery expressions using [1] with attributes. Can somebody please explain what does it mean? Here is a example declare @aa xml set @aa=' 1
Deb
  • 981
  • 13
  • 39
3
votes
1 answer

TSQL How to select employee with skills in xml column

In 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 CONSTRAINT [PK_Employee] PRIMARY KEY…
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178
3
votes
2 answers

T-SQL, XQuery Invalid Column

I'm just learning XQUERY and trying to accomplish what I thought would be very simple. Here's my T-SQL code: DECLARE @XML xml set @xml = '13.0' -- Code below is wrong select…
ccdrm
  • 300
  • 2
  • 9
3
votes
1 answer

Updating XML attribute in SQL Server XML column

I am trying to update a node of in my XML which is stored in a SQL Server XML column, the line below works if my XML is in a XML element but now I somehow need to change it to XML attributes, apparently the line becomes invalid after the…
k80sg
  • 2,443
  • 11
  • 47
  • 84
3
votes
1 answer

Replace node value which occurs multiple places in the XML of SQL Server

I tried with below code to replace the values of user_input_attn_obligee_desc which exists in multiple places in the XML with the value EDWIN CHAND. BEGIN DECLARE @d1 XML = '
3
votes
1 answer

any element in XML schema blocks XQuery

I have the following XML Schema: CREATE XML SCHEMA COLLECTION test AS '
Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212
3
votes
1 answer

How to optimise the 'XQuery' SQL

I have an XML hierarchy like this in an XML type column of a table with 10,000 records-
3
votes
1 answer

XQUERY SQL - How to pass individual node element(s) as variables?

Is there an alternate way to pass node elements dynamically than the one shown below - ? select XMLTable.XMLCOL.query('//*[local-name()=sql:variable("@node")') For e.g., even if I am trying to give the fully qualified path, I do not want to hard…
3
votes
1 answer

Modify XML values identified through cross apply

I've got a data issue with some values stored in an XML column in a database. I've reproduced the problem as the following example: Setup Script: create table XMLTest ( [XML] xml ) --A row with two duff entries insert XMLTest values (' …
Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
3
votes
1 answer

How to extract values from XML without hard coding names of elements using XQuery in SQL Server?

I have xml stored in a table and table with names/paths of the elements I am interested in. I would like to extract values of these elements without hard coding paths and/or names of the elements. Structure of my xml will not change, it will always…
Ilya Berdichevsky
  • 1,249
  • 10
  • 24
3
votes
1 answer

SQL Server XML add attribute if non-existent

I am trying to add an attribute if it does not exist. It should be simple, but I am new to XML XPath/XQuery/etc., so excuse my ignorance. I want to be able to pass XML data and modify it... ALTER FUNCTION [dbo].[ConvertXmlData](@xmlData XML) RETURNS…
3
votes
1 answer

Need a help Local.name(.) xquery function

can any one tell me how Local.name(.) xquery function works. regarding sql construction problem i post a question in a forum and they give me answer. where Local.name(.) xquery function is used but syntax is not clear to me very well. ;with cte…
Thomas
  • 33,544
  • 126
  • 357
  • 626
3
votes
2 answers

Use XQuery to get at this data

I am new to XQuery and am having some problems with it. Here is my example. I have this variable: declare @xmlDoc XML it has the following xml stored in it:
Vaccano
  • 78,325
  • 149
  • 468
  • 850
1 2
3
30 31