0

我有以下 XML

<NewDataSet>
<data name="AC_Capacity_Creation_Notification.Text">
    <value>Activation successfull and sent for approval.</value>
    <comments>AC Capacity</comments>
</data>
<data name="AC_Capacity_Modification_Daily_Notification.Text">
   <value>Approved successfully..</value>
   <comments>AC Capacity</comments>
 </data>
 <data name="AC_Capacity_Modification_Schedule_Notification.Text">
   <value>Are you sure you want to close this form?</value>
   <comments>AC Capacity</comments>
   </data>
 </NewDataSet>

我想将此 XML 中的数据获取到临时表中,我可以从中进一步查询,但无法这样做

我试过这样做:

  EXEC sp_xml_PrepareDocument @intHandle OUTPUT, @XML    

  SELECT * into #tmp FROM OPENXML(@intHandle, '/NewDataset/data',2)

  EXEC sp_xml_removedocument @intHandle   

  drop table #tmp 

但我得到空行

4

2 回答 2

1

只需使用本机 XQuery - 更简单!

DECLARE @Input XML = '<NewDataSet>
<data name="AC_Capacity_Creation_Notification.Text">
    <value>Activation successfull and sent for approval.</value>
    <comments>AC Capacity</comments>
</data>
<data name="AC_Capacity_Modification_Daily_Notification.Text">
   <value>Approved successfully..</value>
   <comments>AC Capacity</comments>
 </data>
 <data name="AC_Capacity_Modification_Schedule_Notification.Text">
   <value>Are you sure you want to close this form?</value>
   <comments>AC Capacity</comments>
   </data>
 </NewDataSet>'

SELECT
    VALUE = NDSData.value('(value)[1]', 'varchar(200)'),
    Comments = NDSData.value('(comments)[1]', 'varchar(200)')
INTO 
    #temp
FROM
    @Input.nodes('/NewDataSet/data') AS Tbl(NDSData) 

给我一个输出:

在此处输入图像描述

于 2012-11-22T07:44:22.810 回答
0

我就是这样做的

 SELECT T.N.value('@name', 'varchar(100)')name,
  T.N.value('value[1]', 'varchar(100)')value
 FROM @XML.nodes('/NewDataSet/data') AS T(N)

它有效..谢谢大家的回答。

于 2012-11-22T09:13:03.603 回答