如何把XML转换成SQL Server临时表

例子才是王道:

 

 1 declare @xml as xml;
 2 set @xml='<root>
 3 <item key="key1" value="1" />
 4 <item key="key2" value="2" />
 5 </root>';
 6 
 7 declare @doc as int;
 8 declare @list as table(key varchar(30), value int);
 9 
10 exec sp_xml_preparedocument @doc out, @xml;
11 
12 
13 insert into @list
14 select * from openxml(@doc, 'root/item')
15 with
16 (
17 key varchar(30),
18 value int
19 )
20 exec sp_xml_removedocument @doc;
21 
22 
23 select * from @list;

 

posted @ 2012-04-17 15:19  托大人  阅读(671)  评论(0编辑  收藏  举报