xquery-sql

Return multiple XML nodes and Custom parent tag using FLWOR XQuery

瘦欲@ 提交于 2019-12-11 17:08:21
问题 I need to get the following output using a FLWOR expression. <oldPlanes> <make>Cessna</make> <model>Centurian</model> <make>Piper</make> <model>Tripacer</model> </oldPlanes> using CREATE TABLE XMLO1 (xDoc XML NOT NULL) INSERT INTO XMLO1 VALUES (' <planes> <plane> <year>1977</year> <make>Cessna</make> <model>Skyhawk</model> <color>Light blue and white</color> </plane> <plane> <year>1975</year> <make>Piper</make> <model>Apache</model> <color>White</color> </plane> <plane> <year>1960</year>

SQL Server performance in xquery with for loop

蹲街弑〆低调 提交于 2019-12-11 14:14:56
问题 I have one sql table with xml column, which holds the value like following xml format <Security xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Dacl> <ACEInformation> <UserName>Authenticated Users</UserName> <Access>Allow</Access> <IsInherited>false</IsInherited> <ApplyTo>This object only</ApplyTo> <Permission>List Contents</Permission> <Permission>Read All Properties</Permission> <Permission>Read Permissions</Permission> </ACEInformation>

how to handle error Subquery returned more than 1 value this example?

房东的猫 提交于 2019-12-11 05:57:49
问题 how to handle error Subquery returned more than 1 value this example? declare @html xml = N'<div itemtype="http://schema.org/Product"><table width="100%" cellspacing="0" cellpadding="2"><tr><td><table><tr><td class="navigation" ><a href="index.php">Battery Adapter</a> > <a href="index.php/cPath/681">Laptop CPU Fan</a> > <a href="index.php/cPath/681_707">ASUS</a> ><a href="product_info.php/products_id/3851">A8 Series</a> </td><td></td></tr></table></td></tr><tr><td><table align="center" class=

TSQL How to select employee with skills in xml column

你。 提交于 2019-12-10 21:08:52
问题 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 CLUSTERED How would i get Employees having C# (case insensitive) programming skills assuming the xml saved in the Skills columns is as below. Could you advice on other functions would help me filter, sort when using xml data type columns <Skills><Skill>C#</Skill>

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

核能气质少年 提交于 2019-12-10 17:56:14
问题 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 code the node elements, instead I would like to pass them individually as parameters. Under the section - Example: Query Using sp_executesql @ http://msdn.microsoft.com/en-us/library/ms345118(v=sql.90).aspx it says - query contains wildcards (*) and

XQuery adding or replacing attribute in single SQL update command

喜你入骨 提交于 2019-12-10 17:24:21
问题 I have a Table with an XML column, I want to update the xml to insert attribute or to change the attribute value if the attribute already exists. Let's say the starting xml is: < d /> Inserting: UPDATE Table set XmlCol.modify('insert attribute att {"1"} into /d[1]') Changing: UPDATE Table set XmlCol.modify('replace value of /d[1]/@att with "1"') insert will fail if the attribute already exists, replace will fail if the attribute doesn't exists. I have tried to use 'if' but I don't think it

Update XML field with no text in T-SQL

眉间皱痕 提交于 2019-12-10 09:23:45
问题 I've come across a problem in updating an SQL field in that what I've written works perfectly for xml nodes with a text present, however it trips up when the node is empty. <filemeta filetype="Video"> <heading>TEST</heading> <description /> </filemeta> This code works fine; UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/heading/text())[1] with "TEST"'); However this breaks; UPDATE filemetaDB SET filemeta.modify('replace value of (/filemeta/description/text())[1] with

Search for multiple values in xml column in SQL

寵の児 提交于 2019-12-10 07:26:21
问题 This is my table BasketId(int) BasketName(varchar) BasketFruits(xml) 1 Gold <FRUITS><FID>1</FID><FID>2</FID><FID>3</FID><FID>4</FID><FID>5</FID><FID>6</FID></FRUITS> 2 Silver <FRUITS><FID>1</FID><FID>2</FID><FID>3</FID><FID>4</FID></FRUITS> 3 Bronze <FRUITS><FID>3</FID><FID>4</FID><FID>5</FID></FRUITS> I need to search for the basket which has FID values 1 and 3 so that in this case i would get Gold and Silver Although i've reached to the result where i can search for a SINGLE FID value like

Questions About Sort Order Using XQuery in SQL Server

南楼画角 提交于 2019-12-07 18:52:07
问题 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 = '<hey i="3"/><hey i="4"/><hey i="0"/>' SELECT t.i.value('.', 'int') FROM @x.nodes('/hey/@i') t(i) I ask because in general SELECT statements do not guarantee an order unless one is provided. Also, if this order is (or is not) guaranteed, is that documented somewhere officially, maybe on Microsoft's

XQuery: Finding rows which contain specified xml data

好久不见. 提交于 2019-12-07 17:53:55
问题 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: <Record> <RecordField ID="31" Name="Barcode1" DataTypeId="5" TypeName="String" Decimals="0" Format="" Mandatory="False">ABC123</RecordField> </Record> 2: <Record> <RecordField ID="15" Name="Field 1" DataTypeId="7" TypeName="Boolean" Decimals="0" Format="" Mandatory="False">true</RecordField>