xquery-sql

Replace the XML element with new Element in SQL server

别等时光非礼了梦想. 提交于 2019-12-23 01:42:08
问题 Replace <apipAccessbility> element of this content with a new element in multiple rows with a column of type XML : <Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"> <ItemBody>xyz</ItemBody> <apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0"> <accessibilityInfo> Blablah </accessibilityInfo> </apipAccessibility> </Item> Once element is updated it should look like this: <Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">

XQuery and Node Ids

拥有回忆 提交于 2019-12-20 05:27:51
问题 I have this variable: declare @xmlDoc XML it has the following xml stored in it: <?xml version="1.0" encoding="utf-8"?> <NewDataSet> <Table1> <Sharedparam>shared</Sharedparam> <Antoher>sahre</Antoher> <RandomParam2>Good stuff</RandomParam2> <MoreParam>and more</MoreParam> <ResultsParam>2</ResultsParam> </Table1> <Table1> <RandomParam2>do you</RandomParam2> <MoreParam>think</MoreParam> <ResultsParam>2</ResultsParam> </Table1> <Table1> <Sharedparam>Last</Sharedparam> <Antoher> Set </Antoher>

Compare two sets of XML data using XQuery in SQL Server

此生再无相见时 提交于 2019-12-18 15:50:08
问题 Suppose I store employee data in a xml column in my log table. Sometimes data is also updated in the xml column from a stored procedure. Here is the sample example DECLARE @XML1 XML DECLARE @XML2 XML SET @XML1 = '<NewDataSet> <Employee> <EmpID>1005</EmpID> <Name> keith </Name> <DOB>12/02/1981</DOB> <DeptID>ACC001</DeptID> <Salary>10,500</Salary> </Employee> </NewDataSet>' SET @XML2 = '<NewDataSet> <Employee> <EmpID>1006</EmpID> <Name> keith </Name> <DOB>05/02/1981</DOB> <DeptID>ACC002</DeptID

XQUERY - How to use the sql:variable in 'value()' function?

不想你离开。 提交于 2019-12-18 06:14:31
问题 The query below is trying to select a child node of a given Node. How do I use a variable instead of hard coding the child node such that I can pass them as parameters in a SProc? declare @T table(XMLCol xml) insert into @T values ('<Root xmlns="http://tempuri.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Elem1 type="T1"> <Name type="string" display="First name">John</Name> <TimeZone display="Time zone"> <children> <DisplayName type="string" display="Display name">GMT Standard

XQUERY - How to use the sql:variable in 'value()' function?

本小妞迷上赌 提交于 2019-12-18 06:13:11
问题 The query below is trying to select a child node of a given Node. How do I use a variable instead of hard coding the child node such that I can pass them as parameters in a SProc? declare @T table(XMLCol xml) insert into @T values ('<Root xmlns="http://tempuri.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Elem1 type="T1"> <Name type="string" display="First name">John</Name> <TimeZone display="Time zone"> <children> <DisplayName type="string" display="Display name">GMT Standard

Concat XML nodes using XQuery

痞子三分冷 提交于 2019-12-13 16:08:48
问题 I required the following output <name>Thomas Mapother</name> <name>Tom Cruise</name> using the below XML using XQuery FLOWR Expressions. INSERT INTO XMLO1 VALUES ('<Contact> <Names> <Name Type = "Legal"> <First>Thomas</First> <Middle>T</Middle> <Last>Mapother</Last> </Name> <Name Type = "Stage"> <First>Tom</First> <Middle>C</Middle> <Last>Cruise</Last> </Name> </Names> </Contact>') I tried the below query. But it returns a different output. SELECT xDoc.query('let $names := Contact/Names/Name

MarkLogic: XQuery to Get Values from XML Documents?

↘锁芯ラ 提交于 2019-12-13 14:18:02
问题 I have the following XML document loaded in MarkLogic database: <x:books xmlns:x="urn:books"> <book id="bk001"> <author>Writer</author> <title>The First Book</title> <genre>Fiction</genre> <price>44.95</price> <pub_date>2000-10-01</pub_date> <review>An amazing story of nothing.</review> </book> <book id="bk002"> <author>Poet</author> <title>The Poet's First Poem</title> <genre>Poem</genre> <price>24.95</price> <review>Least poetic poems.</review> </book> </x:books> I am new to XQuery. How

Search for multiple values in xml column in SQL

瘦欲@ 提交于 2019-12-13 12:29:11
问题 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

Search for multiple values in an xml column

天涯浪子 提交于 2019-12-13 07:38:56
问题 Environment: SQL Server 2012. Primary and secondary (value) index is built on xml column. Say I have a table Message with xml column WordIndex. I also have a table Word which has WordId and WordText. Xml for Message.WordIndex has the following schema: <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com"> <xs:element name="wi"> <xs:complexType> <xs:sequence> <xs:element maxOccurs=

Referencing the Current Context in a T-SQL nodes() XQuery

旧时模样 提交于 2019-12-13 04:19:10
问题 Is it possible to effect a join between two T-SQL nodes() calls by filtering the second nodes() based on the context node of the first? In the example below, I'm trying to return a table showing PersonID , Name and Position . My attempt at referencing the @id of the first nodes() 's context node in the second nodes() XQuery statement doesn't work. No position names are returned. Any ideas? Thank you! DECLARE @xml xml = '<Root> <People> <Person id="1">Frank</Person> <Person id="2">Joe</Person>