sqlxml

Read XML data into hierarchical tables

橙三吉。 提交于 2019-12-24 11:07:25
问题 I have XML data that is used to store quiz results. I need to convert this into two tables, one containing the questions, and the other containing the answers, but crucially, have a relation between them. Currently this relation only exists in the XML structure (there are no ID values, etc.). After a day of research and testing out different approaches, I've got as far as extracting the two parts, but cannot figure out how to create the hierarchy: declare @xml xml = N'<quizresult> <question>

How to return XML from SQL Server 2008 that is structured with multiple selections sharing a common parent

£可爱£侵袭症+ 提交于 2019-12-22 06:36:28
问题 I've tried using "FOR XML PATH", "FOR XML EXPLICIT" and "FOR XML AUTO" but the data is never structured with the correct heirarchy. Basically, I have one parent table (Customers) and 3 child tables. Each table has a customerid column. There is a one-to-many relationship from the Customers table to each of the 3 child tables. As a mock example, I have a parent "Customers" table, and I have 3 other tables - Products, Hobbies and Vehicles - all related to the Customers table by a customerid.

SQL Server : FOR XML sorting control by attribute

最后都变了- 提交于 2019-12-19 02:52:52
问题 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

SQL UNION FOR XML name output column

痞子三分冷 提交于 2019-12-18 18:56:40
问题 I'm trying to generate an XML output from SQL and need to use a UNION statement and also name the output column. I had this working before when I didn't need to use a UNION statement using: select( SELECT [CompanyName], [Address1], [Address2], [Address3], [Town], [County], [Postcode], [Tel], [Fax], [Email], [LocMap] FROM [UserAccs] FOR XML PATH ('AccountDetails'), root ('Root') ) as XmlOutput Which named the output XML column as XmlOutput I am now trying: select( SELECT [CompanyName],

XML output from MySQL

倖福魔咒の 提交于 2019-12-17 13:53:24
问题 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],

XML output from MySQL

↘锁芯ラ 提交于 2019-12-17 13:53:13
问题 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],

XPath Query to find supplier name through an XML table

我们两清 提交于 2019-12-13 09:51:31
问题 I am trying to find out the cities where there is a supplier with the name of Herman. We are using XPath through Microsoft SQL Server Management Studio. I am not a CIS major and I have no idea where to start. So that's why I'm asking for help... I have the following table created: CREATE TABLE Tb_Supplier( XMLColumn XML) GO INSERT Tb_Supplier VALUES( '<SuppliersList> <Supplier name="Joe"> <City>Paris</City> <Product name="Airplane"/> <Product name="Milk"/> <Product name="TV"/> <Product name=

how to using distinct in XML SQL using stored procedure

有些话、适合烂在心里 提交于 2019-12-13 05:47:53
问题 SELECT DISTINCT CD.CASE_NO AS CaseNumber , CE.PROCEEDING_ID AS ProceedingId, PR.AC_STATE_CD AS ForeclosureStatecode, 0 AS STATUS, GETDATE() AS CreatedDate, 1 AS CreatedBy, GETDATE() AS ModifiedDate, 1 AS ModifiedBy, ( select * from TBL_PROPERTY FOR XML PATH('T') ) from TBL_CASE_DETAIL CD WITH(NOLOCK) INNER JOIN TBL_AUCTION_DETAIL AD WITH(NOLOCK) ON AD.CASE_DETAIL_ID = CD.CASE_DETAIL_ID LEFT JOIN TBL_AUCTION_PROPERTY_MAPPING TAPM WITH(NOLOCK) ON TAPM.AUCTION_ID = AD.AUCTION_ID LEFT JOIN TBL

Importing and parsing a large XML file in SQL Server (when “normal” methods are rather slow)

无人久伴 提交于 2019-12-13 05:16:22
问题 I have a large XML file that I need to import and parse into tabular structure ("flatten") in SQL Server. By "large" I mean a file that is around 450 MB, contains up to 6-7 nested levels and lots of elements, ~300. I tried parsing the file both with OPENXML and Xml.Nodes . Both of the methods are slow. A partial query which reads a parent element and it's nested grandchildren takes several minutes if not dozens to run. I tried using the SQLXML Bulk Load method. Unfortunately I couldn't -

SELECT XML FROM TABLE IN SQL SERVER

穿精又带淫゛_ 提交于 2019-12-12 20:31:46
问题 I have XML stored in my table. This table has columns id type int, and value type XML. I'm using SQL Server 2012. XML looks like this: <?xml version="1.0" encoding="utf-16"?> <Weather> <Forecast> <Description>sky is clear</Description> <Date>6.9.2013 23:50:36</Date> <MinTemp>13</MinTemp> <MaxTemp>13</MaxTemp> <Pressure>995</Pressure> <Humidity>68</Humidity> </Forecast> </Weather> This XML can have up to then Forecast parts. How can I with simple SELECT statement get for instance Humidity