sqlxml

SQL XML Column - Cross Apply to Produce Multiple Rows based on XML 1 to many

一世执手 提交于 2021-02-08 08:32:33
问题 I've been studying this post, but I'm still not understanding the "cross apply" with XML data. Also this post. I have an Xml column that contains a passenger, and the multiple flights and flight-legs on his ticket. This is what I have working after much fiddling: Select xmlDoc.value('(//Passenger[1]/text())[1]', 'varchar(100)') as Passenger, XmlData2.xmlDoc2.query('//FlightLeg') as xmlDoc2b FROM xmlData as t CROSS APPLY t.xmlDoc.nodes('//FlightLeg') AS XmlData2(xmlDoc2) where xmlSchema =

Query XML data for information based on a sibling value

醉酒当歌 提交于 2020-08-11 01:50:02
问题 I have the following XML data, which I have zero control over. Note that it's basically a collection of property groups. I need to select the value of one property where the value of another property is 'true'. The problem is, there's nothing to group on, and I cannot figure out how to associate things correctly. Here's the XML Data, and the query I came up with so far: DECLARE @xml xml = ' <Container> <Collection> <ItemName>SomeItem</ItemName> <IsDeletable>true</IsDeletable> <IsPersisted

Query XML data for information based on a sibling value

只谈情不闲聊 提交于 2020-08-11 01:49:11
问题 I have the following XML data, which I have zero control over. Note that it's basically a collection of property groups. I need to select the value of one property where the value of another property is 'true'. The problem is, there's nothing to group on, and I cannot figure out how to associate things correctly. Here's the XML Data, and the query I came up with so far: DECLARE @xml xml = ' <Container> <Collection> <ItemName>SomeItem</ItemName> <IsDeletable>true</IsDeletable> <IsPersisted

XML Column - three levels hierarchy - with Cross Apply

独自空忆成欢 提交于 2020-06-29 06:42:22
问题 My prior question was solved here. Now I'm adding one more level of complexity to it - data that is nested parent, child, grandchild. You can see and run sample here: https://dbfiddle.uk/?rdbms=sqlserver_2019&fiddle=df2766c95383d4c8c2d1f55539634341 Sample Code, where Leg1 might be the trip out, and Leg2 might be the trip back. Each leg can have one or more flights. DECLARE @xml XML=' <Reservation> <Name>Neal</Name> <Leg seq=''1''> <Flight>12</Flight> </Leg> <Leg seq=''2''> <Flight>34</Flight>

SQL XML Query slower with XML Indexes

房东的猫 提交于 2020-06-28 05:16:29
问题 I have a query that looks like the following: SELECT p.pProfileXml.value(''(Profile/ssn)[1]'', ''int'') ssn, p.pProfileXml.value(''(Profile/date-birth)[1]'', ''date'') [date-birth], p.pProfileXml.value(''(Profile/bad-field)[1]'', ''varchar(max)'') [bad-field], p.pProfileXml.value(''(Profile/cb-bal)[1]'', ''float'') [e1_f1], p.pProfileXml.value(''(Profile/date-hire-orig)[1]'', ''date'') [e1_f2], p.pProfileXml.value(''(Profile/date-birth)[1]'', ''date'') [e2_f1] FROM Profile p WHERE p.pgKey =

SQL Pivot using an XML column

我的梦境 提交于 2020-01-24 21:18:05
问题 Does anyone have an example of a pivot using a table with an XML column in it - specifically turning some of the elements in the xml column into a column in the pivot table? I'm trying to build one, but the syntax is killing me; xml in sql is damn hard to work with, compared to xml in C#. I suspect this is impossible, but it wouldn't hurt to check :) 回答1: Here is a simple example that has Stores with Product details stored in xml. The pivot is at the bottom which shows the stores and a sum of

SQL multiple SELECT query with xmlagg function- Data not pulled in the required fashion

纵然是瞬间 提交于 2020-01-24 19:07:52
问题 My data in Oracle is something like this NAME | DEP_VALUE | ID_DEP Amy 1 AA1234 Bob 2 BB4321 Clara 1 CC5678 Clara 2 CC7890 John 1 JJ6543 John 2 JJ7865 John 3 JJ7654 Tom 1 TT0987 Tom 2 TT6541 Tom 3 TT4087 Tom 4 TT3409 I need the data to be pulled in this fashion NAME | DEP_VALUE | ID_DEP Amy 1 AA1234 Bob 2 BB4321 Clara 1;2 CC5678;CC7890 John 1;2;3 JJ6543;JJ7865;JJ7654 Tom 1;2;3;4 TT0987;TT6541;TT4087;TT3409 My query is as follows SELECT name, Rtrim(Xmlagg (Xmlelement (e, dep_value || ';'))

Convert C# 2.0 System.Data.SqlTypes.SqlXml object into a System.Xml.XmlNode

让人想犯罪 __ 提交于 2020-01-13 19:26:27
问题 I seem to always have problems with converting data to and from XML in C#. It always wants you to create a full XMLDocument object even when you think you shouldn't have to. In this case I have a SQLXML column in a MS SQL 2005 server that I am trying to pull out and push into a function that requires an XMLNode as a parameter. You would think this would be easy, but outside of converting it to a string and creating a new XMLNode object I cannot figure out the right way to do it. I can use an

How to Update XML in SQL based on values in that XML

懵懂的女人 提交于 2020-01-05 11:05:10
问题 I have to update XML of table based on some conditions of that XML. Sample XML: <CountryValues> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>1</Month> <PlaceValue>0</PlaceValue> </CountryRow> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>2</Month> <PlaceValue>0</PlaceValue> </CountryRow> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>3</Month> <PlaceValue>0</PlaceValue> <

How to Update XML in SQL based on values in that XML

北战南征 提交于 2020-01-05 11:04:29
问题 I have to update XML of table based on some conditions of that XML. Sample XML: <CountryValues> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>1</Month> <PlaceValue>0</PlaceValue> </CountryRow> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>2</Month> <PlaceValue>0</PlaceValue> </CountryRow> <CountryRow> <CountryName>Brazil</CountryName> <PlaceName>Place 1</PlaceName> <Month>3</Month> <PlaceValue>0</PlaceValue> <