SQL splits XML structure through cursors

Source: Internet
Author: User

-----------------------define a cursor variable------------------------------------------
DECLARE @propertyid INT
DECLARE @propertyname VARCHAR (50)
DECLARE @xml NVARCHAR (1000)
DECLARE top3_cursor Cursor SCROLL for
--------------------------defines the end of the cursor-----------------------------
SELECT s.id, S.name, CAST (Propertyvalueschema as VARCHAR) Propertyvalueschema
From Styleproperty s INNER JOIN (SELECT MAX (a.id) ID, a.name
FROM dbo. Styleproperty a INNER JOIN dbo. Stylepartsgroup b on a.groupid = b.ID
WHERE propertyvalueschema.exist ('//valueschema//select//@mode ') =1
GROUP by A.name) b on s.id = b.ID

OPEN Top3_cursor
FETCH NEXT from Top3_cursor to @propertyid, @propertyname, @xml
while (@ @FETCH_STATUS =0)
BEGIN

-----------------------------Body-------------------------------------


DECLARE @idoc INT


PRINT @xml
EXEC sp_xml_preparedocument @idoc OUTPUT, @xml
--Execute A SELECT statement using OPENXML rowset provider.
INSERT into T1
SELECT @propertyid PropertyId, @propertyname PropertyName, *
From OPENXML (@idoc, '/valueschema/select/items/item ', 1)
With (
Codekey INT ' @key ',
Codename varchar (+) ' @name '
)
EXEC sp_xml_removedocument @idoc
------------------------------------Body End---------------------------
FETCH NEXT from Top3_cursor to @propertyid, @propertyname, @xml
END

-----------------------Footer-----------------------
Close Top3_cursor
Deallocate top3_cursor
---------------Footer End----------------------

--------------------------------------------End Cursor--------------------

SQL splits XML structure through cursors

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.