sqlxml

Bulk insert nested xml with foreign key as identity column of first table

情到浓时终转凉″ 提交于 2019-12-01 05:22:24
问题 I have an xml as follows: <Records> <Record> <Name>Best of Pop</Name> <Studio>ABC studio</Studio> <Artists> <Artist> <ArtistName>John</ArtistName> <Age>36</Age> </Artist> <Artist> <ArtistName>Jessica</ArtistName> <Age>20</Age> </Artist> </Artists> </Record> <Record> <Name>Nursery rhymes</Name> <Studio>XYZ studio</Studio> <Artists> <Artist> <ArtistName>Judy</ArtistName> <Age>10</Age> </Artist> <Artist> <ArtistName>Rachel</ArtistName> <Age>15</Age> </Artist> </Artists> </Record> </Records> This

SQL 2012 - iterate through an XML list (better alternative to a WHILE loop)

耗尽温柔 提交于 2019-12-01 03:05:45
问题 Using SQL 2012 & getting XML passed into a stored procedure that must take that input & write a row to the table for each of the items that is in a section of the XML that is passed to the stored procedure. The XML looks like: <MyXML> <MyMsg>My Text Message</MyMsg> <MsgTime>2013-09-25 10:52:37.098</MsgTime> <SendToList> <SendTo>John</SendTo> <SendTo>James</SendTo> <SendTo>Rob</SendTo> <SendTo>Pete</SendTo> <SendTo>Sam</SendTo> </SendToList> </MyXML> The output of the stored procedure should

SQL Server : FOR XML sorting control by attribute

安稳与你 提交于 2019-11-30 20:06:15
I am generating a XML file from a SQL Server query. I have some problem about sorting elements issues. For example, there is simple code as below. <test> <tree abc="123"/> <tree abc="789"/> <tree-order abc="456"/> </test> As you can see tree and tree-order are different elements and I want to sort by attributes as <test> <tree abc="123"/> <tree-order abc="456"/> <tree abc="789"/> </test> like this. Anyone has good idea to solve this problem? Thank you. Sorry I have detail question as below AS is <Main> <test> <tree abc="123"/> <tree abc="789"/> <tree-order abc="456"/> </test> <test> <tree abc=

Using OPENXML in SQL Server 2008 stored proc - INSERT order differs from XML document

独自空忆成欢 提交于 2019-11-29 15:25:16
I'm using SQL Server 2008's XML-parsing abilities to iterate through an XML document and perform an INSERT each element. However, my stored procedure appears to be inserting each element into the table in an order which differs from the order in the document. Furthermore, the more times I try this, the INSERT order seems to change. Here's a sample of the XML document - nothing too fancy going on here. <ts> <t id="36a3c8c1-b958-42f0-82d1-dfa6bf9b99a1" encryptedAccountId="fQ/XF8lpeR9wEDUV3yMzvQ==" uploaded="2012-04-03T15:49:19.9615097Z" visible="1"> <tv fieldId="301" officialValue="0, 0"

SQL Server: Two-level GROUP BY with XML output

十年热恋 提交于 2019-11-28 11:27:59
I have a table of hierarchical data that I am trying to select as a single, grouped XML value: Columns: Id, Type, SubType, SubSubType Sample data: Id Type Subtype SubSubType 1 Product Documentation Brochures Functional Brochures 2 Product Documentation Brochures Fliers 3 Product Documentation Data Sheets and Catalogs Data Sheets 4 Product Documentation Data Sheets and Catalogs Catalogs 5 Other Documentation Other classification User Guides For the above data, I would like to output the following xml: <AllTypes> <Type name="Product Documentation"> <SubType name="Brochures"> <SubSubType name=

Using OPENXML in SQL Server 2008 stored proc - INSERT order differs from XML document

对着背影说爱祢 提交于 2019-11-28 09:11:24
问题 I'm using SQL Server 2008's XML-parsing abilities to iterate through an XML document and perform an INSERT each element. However, my stored procedure appears to be inserting each element into the table in an order which differs from the order in the document. Furthermore, the more times I try this, the INSERT order seems to change. Here's a sample of the XML document - nothing too fancy going on here. <ts> <t id="36a3c8c1-b958-42f0-82d1-dfa6bf9b99a1" encryptedAccountId="fQ/XF8lpeR9wEDUV3yMzvQ

modify(replace) XML for conditions

本小妞迷上赌 提交于 2019-11-28 05:43:00
问题 I want to replace the value in an element tag, depending on its value, as well as the value of another element(in the same level as said element), both elements being inside the same parent element tag everywhere(Every parent tag is unique due to its own ID attribute). I want to do the change at various locations of this XML variable, in a stored procedure. Being a first timer at this, I am stuck with how i could modify the elements throughout the xml. Both elements are present in the same

XML output from MySQL

纵然是瞬间 提交于 2019-11-27 15:33:50
is there any chance of getting the output from a MySQL query directly to XML? Im referring to something like MSSQL has with SQL-XML plugin, for example: SELECT * FROM table WHERE 1 FOR XML AUTO returns text (or xml data type in MSSQL to be precise) which contains an XML markup structure generated according to the columns in the table. With SQL-XML there is also an option of explicitly defining the output XML structure like this: SELECT 1 AS tag, NULL AS parent, emp_id AS [employee!1!emp_id], cust_id AS [customer!2!cust_id], region AS [customer!2!region] FROM table FOR XML EXPLICIT which

How to query for Xml values and attributes from table in SQL Server?

非 Y 不嫁゛ 提交于 2019-11-27 06:35:29
I have a table that contains a Xml column: SELECT * FROM Sqm A sample of the xml data of a row would be: <Sqm version="1.2"> <Metrics> <Metric id="TransactionCleanupThread.RecordUsedTransactionShift" type="timer" unit="µs" count="1" sum="21490" average="21490" minValue="73701" maxValue="73701" >73701</Metric> <Metric id="TransactionCleanupThread.RefundOldTrans" type="timer" unit="µs" count="1" sum="184487" average="184487" minValue="632704" maxValue="632704" >632704</Metric> <Metric id="Database.CreateConnection_SaveContextUserGUID" type="timer" unit="µs" count="2" sum="7562" average="3781"

SQL Server: Two-level GROUP BY with XML output

二次信任 提交于 2019-11-27 06:16:35
问题 I have a table of hierarchical data that I am trying to select as a single, grouped XML value: Columns: Id, Type, SubType, SubSubType Sample data: Id Type Subtype SubSubType 1 Product Documentation Brochures Functional Brochures 2 Product Documentation Brochures Fliers 3 Product Documentation Data Sheets and Catalogs Data Sheets 4 Product Documentation Data Sheets and Catalogs Catalogs 5 Other Documentation Other classification User Guides For the above data, I would like to output the