XML Stream Query

Source: Internet
Author: User
In SQLServer2000, Microsoft released the Transact-SQL keywords FORXML and OPENXML. FORXML is an extension of the SELECT statement. It returns the XML stream query results shown in the following example. SELECTProductID, ProductNameFROMProductsProductFORXMLAUTO this query returns

In SQLServer2000, Microsoft released the Transact-SQL keywords FORXML and OPENXML. FORXML is an extension of the SELECT statement. It returns the XML stream query results shown in the following example. SELECT ProductID, ProductName FROM Products Product for xml auto this query returns

In SQL Server 2000, Microsoft released the Transact-SQL keywords FOR XML and OPENXML. For xml is an extension of the SELECT statement. It returns the XML streaming query results shown in the following example.
SELECT ProductID, ProductName
FROM Products Product
FOR XML AUTO
This query returns an XML snippet shown in the following example:


The OPENXML function is opposite to the for xml Condition Clause. It creates a rowset FOR the XML document, as shown in the following example:
DECLARE @ doc nvarchar (1000)
SET @ doc ='


'
DECLARE @ xmlDoc integer
EXEC sp_xml_preparedocument @ xmlDoc OUTPUT, @ doc
SELECT * FROM
OPENXML (@ xmlDoc, 'order/item', 1)
WITH
(OrderID integer '../@ OrderID ',
ProductID integer,
Quantity integer)
EXEC sp_xml_removedocument @ xmlDoc
Note the usage of using the sp_xml_preparedocument and sp_xml_removedocument stored procedures to create a memory display for the node tree of the XML document. The Transact-SQL code returns the following rowset.
OrderID ProductID Quantity
1011 1 2
1011 2 1

<无>
  SELECT ProductID, ProductName   FROM Products Product   FOR XML AUTO
DECLARE @doc nvarchar(1000)SET @doc = '
     
      
     
  'DECLARE @xmlDoc integerEXEC sp_xml_preparedocument @xmlDoc OUTPUT, @docSELECT * FROMOPENXML (@xmlDoc, 'Order/Item', 1)WITH(OrderID integer '../@OrderID',ProductID integer,Quantity integer)EXEC sp_xml_removedocument @xmlDoc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.