zoukankan      html  css  js  c++  java
  • sql 通过游标 拆分xml结构

    -----------------------定义游标变量------------------------------------------
      DECLARE @propertyid INT
      DECLARE @propertyname VARCHAR(50)
      DECLARE @xml NVARCHAR(1000)
      DECLARE top3_Cursor CURSOR SCROLL FOR
       --------------------------定义游标结束-----------------------------
       SELECT s.id, s.name, CAST(PropertyValueSchema AS VARCHAR(1000)) 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 INTO @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(100)  '@name'
              )
    EXEC sp_xml_removedocument @idoc
       ------------------------------------body end---------------------------
       FETCH NEXT FROM top3_Cursor INTO @propertyid,@propertyname,@xml
       END
      
       -----------------------footer-----------------------
       close top3_Cursor
     DEALLOCATE  top3_Cursor
       ---------------footer end----------------------
     
     --------------------------------------------end  cursor--------------------

  • 相关阅读:
    mac shell终端编辑命令行快捷键——行首行尾
    mac appium 启动genymotion
    mac eclipse 执行adb 命令,提示command not fount
    java jsch 登录linux系统避免手动输入Yes 或Always
    mac 安装android sdk
    内容选择器
    增强基本选择器[selector_3.html]
    层次选择器[selector_2.html]
    基本选择器
    jquery 入门与知识
  • 原文地址:https://www.cnblogs.com/Impulse/p/5149754.html
Copyright © 2011-2022 走看看