将XML格式的数据写入一个临时表

DECLARE @XML AS XML,@hDoc AS INT,@SQL NVARCHAR (MAX)  SELECT @XML = N'<Root><tblStockMovementHeader>
<intRowNum>1</intRowNum><intSourceCurrentRowVersion>78001</intSourceCurrentRowVersion><intSourceSysID>1007</intSourceSysID><intCurrentRowVersion>78001</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>1007</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>AO00000003</MovementNo><MovementDate>2015-01-08T00:00:00</MovementDate><DocTypeCode>AO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABMLE=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-01-08T15:39:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-01-08T15:39:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>2</intRowNum><intSourceCurrentRowVersion>78046</intSourceCurrentRowVersion><intSourceSysID>1008</intSourceSysID><intCurrentRowVersion>78046</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>1008</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>AO00000004</MovementNo><MovementDate>2015-01-08T00:00:00</MovementDate><DocTypeCode>AO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABMN4=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-01-08T15:59:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-01-08T15:59:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader><intRowNum>3</intRowNum><intSourceCurrentRowVersion>105095</intSourceCurrentRowVersion><intSourceSysID>2007</intSourceSysID><intCurrentRowVersion>105095</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>2007</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000001</MovementNo><MovementDate>2015-03-03T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABmoc=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-03T12:47:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-03T12:47:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader><intRowNum>4</intRowNum><intSourceCurrentRowVersion>105106</intSourceCurrentRowVersion><intSourceSysID>2009</intSourceSysID><intCurrentRowVersion>105106</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>2009</SysID><MovementShopCode>MYSH001</MovementShopCode><OrgNo>TO00000001</OrgNo><MovementNo>TI00000001</MovementNo><MovementDate>2015-03-04T00:00:00</MovementDate><DocTypeCode>TI</DocTypeCode><MovementDirection>1</MovementDirection><MovementStatus>COMP</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>1</HandleVersion><FromShop>MYSH002</FromShop><ToShop>MYSH001</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABmpI=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-04T11:53:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-04T11:53:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>5</intRowNum><intSourceCurrentRowVersion>105109</intSourceCurrentRowVersion><intSourceSysID>2010</intSourceSysID><intCurrentRowVersion>105109</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>2010</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000002</MovementNo><MovementDate>2015-03-04T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABmpU=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-04T14:20:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-04T14:20:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>6</intRowNum><intSourceCurrentRowVersion>106007</intSourceCurrentRowVersion><intSourceSysID>3008</intSourceSysID><intCurrentRowVersion>106007</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3008</SysID><MovementShopCode>MYSH001</MovementShopCode><OrgNo>TO00000002</OrgNo><MovementNo>TI00000002</MovementNo><MovementDate>2015-03-09T00:00:00</MovementDate><DocTypeCode>TI</DocTypeCode><MovementDirection>1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>1</HandleVersion><FromShop>MYSH002</FromShop><ToShop>MYSH001</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABnhc=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-09T11:04:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-09T11:04:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader><intRowNum>7</intRowNum><intSourceCurrentRowVersion>106010</intSourceCurrentRowVersion><intSourceSysID>3009</intSourceSysID><intCurrentRowVersion>106010</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3009</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000003</MovementNo><MovementDate>2015-03-09T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABnho=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-09T15:41:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-09T15:41:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>8</intRowNum><intSourceCurrentRowVersion>106020</intSourceCurrentRowVersion><intSourceSysID>3011</intSourceSysID><intCurrentRowVersion>106020</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3011</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000005</MovementNo><MovementDate>2015-03-10T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>2</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABniQ=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-10T10:17:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-10T10:17:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>9</intRowNum><intSourceCurrentRowVersion>106023</intSourceCurrentRowVersion><intSourceSysID>3012</intSourceSysID><intCurrentRowVersion>106023</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3012</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000006</MovementNo><MovementDate>2015-03-10T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABnic=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-10T10:34:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-10T10:34:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>10</intRowNum><intSourceCurrentRowVersion>106025</intSourceCurrentRowVersion><intSourceSysID>3013</intSourceSysID><intCurrentRowVersion>106025</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3013</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000007</MovementNo><MovementDate>2015-03-10T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABnik=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-10T10:46:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-10T10:46:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>11</intRowNum><intSourceCurrentRowVersion>106031</intSourceCurrentRowVersion><intSourceSysID>3014</intSourceSysID><intCurrentRowVersion>106031</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3014</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000008</MovementNo><MovementDate>2015-03-10T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABni8=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-10T10:49:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-10T10:49:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader><tblStockMovementHeader>
<intRowNum>12</intRowNum><intSourceCurrentRowVersion>106014</intSourceCurrentRowVersion><intSourceSysID>3010</intSourceSysID><intCurrentRowVersion>106014</intCurrentRowVersion><strSourceLocationCode>MYSH001</strSourceLocationCode><strSourceMachineCode>01</strSourceMachineCode><SysID>3010</SysID><MovementShopCode>MYSH001</MovementShopCode><MovementNo>TO00000004</MovementNo><MovementDate>2015-03-10T00:00:00</MovementDate><DocTypeCode>TO</DocTypeCode><MovementDirection>-1</MovementDirection><MovementStatus>NEW</MovementStatus><MovementVersion>1</MovementVersion><HandleVersion>0</HandleVersion><FromShop>MYSH001</FromShop><ToShop>MYSH002</ToShop><LocationCode>MYSH001</LocationCode><MachineCode>01</MachineCode><MarkDel>0</MarkDel><CurrentRowVersion>AAAAAAABnh4=</CurrentRowVersion><IsSource>1</IsSource><AllowPublishUp>1</AllowPublishUp><AllowPublishDown>1</AllowPublishDown><SourceTier>99</SourceTier><SourceLocationCode>MYSH001</SourceLocationCode><SourceMachineCode>01</SourceMachineCode><CreateDate>2015-03-10T09:46:00</CreateDate><CreateBy>admin</CreateBy><UpDateDate>2015-03-10T09:46:00</UpDateDate><UpDateBy>admin</UpDateBy></tblStockMovementHeader></Root>'  
EXEC sp_xml_preparedocument @hDoc OUTPUT,@XML  Select * Into #tmptblStockMovementHeader From OpenXML(@hDoc,'Root/tblStockMovementHeader',3)  With (   [intRowNum] int,[intSourceCurrentRowVersion] bigint,[intSourceSysID] bigint,[intCurrentRowVersion] bigint,[strSourceLocationCode] nvarchar(30),[strSourceMachineCode] nvarchar(10),[SysID] [int],[MovementShopCode] [nvarchar](10),[OrgNo] [nvarchar](50),[MovementNo] [nvarchar](10),[MovementDate] [smalldatetime],[DocTypeCode] [nvarchar](50),[MovementDirection] [int],[DocRouteCode] [nvarchar](10),[Remarks] [nvarchar](255),[MovementStatus] [varchar](16),[MovementVersion] [int],[HandleVersion] [int],[FromShop] [nvarchar](50),[FromSupplier] [nvarchar](50),[ToShop] [nvarchar](50),[ToSupplier] [nvarchar](50),[LocationCode] [nvarchar](30),[MachineCode] [nvarchar](10),[MarkDel] [int],[CurrentRowVersion] [timestamp],[ParentSysID] [int],[ParentCurrentRowVersion] [bigint],[SourceSysID] [int],[SourceCurrentRowVersion] [bigint],[IsSource] [smallint],[AllowPublishUp] [smallint],[AllowPublishDown] [smallint],[SourceTier] [int],[SourceLocationCode] [nvarchar](30),[SourceMachineCode] [nvarchar](10),[RecFromLocationCode] [nvarchar](30),[RecFromMachineCode] [nvarchar](10),[CreateDate] [smalldatetime],[CreateBy] [varchar](50),[UpDateDate] [smalldatetime],[UpDateBy] [varchar](50)  )  
EXEC sp_xml_removedocument @hDoc  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇