-----------------------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