我正在尝试解析这一点。我希望每个事件都有一个记录,所以我需要一种方法来分别查询每个事件。
但我希望它看起来像这样:
Event Name || ID || Timestamp || process_utilization
---------------------------------------------------------------------------------------------
scheduler_monitor_system_heal_ring_buffer_recorded || 0 || 0 || 33
这是 XML:
<events>
<session startTime="2012-09-06T10:48:15.373" droppedEvents="0" largestDroppedEvent="0">
<RingBufferTarget truncated="0" processingTime="0" totalEventsProcessed="14" eventCount="14" droppedCount="0" memoryUsed="3994">
<event name="scheduler_monitor_system_health_ring_buffer_recorded" package="sqlos" timestamp="2012-09-19T16:46:33.091Z">
<data name="id">
<type name="uint32" package="package0" />
<value>0</value>
</data>
<data name="timestamp">
<type name="uint64" package="package0" />
<value>0</value>
</data>
<data name="process_utilization">
<type name="uint32" package="package0" />
<value>33</value>
</data>
</event>
<event name="resource_monitor_ring_buffer_recorded" package="sqlos" timestamp="2012-09-19T16:46:38.386Z">
<data name="id">
<type name="uint32" package="package0" />
<value>0</value>
</data>
</event>
</RingBufferTarget>
</session>
</events>
编辑:或者,如果我们可以返回看起来像这样的行,那就太好了:
scheduler_monitor_system_heal_ring_buffer_recorded || id || 0
scheduler_monitor_system_heal_ring_buffer_recorded || timestamp || 0
scheduler_monitor_system_heal_ring_buffer_recorded || process_utilization|| 33
编辑:(谢谢,马克)使用马克的代码,我得到了我想要的 98% - 只需要事件名称。
SELECT
DataName = Evt.value('@name[1]', 'varchar(50)'),
TypeName= Evt.value('type[1]/@name[1]', 'varchar(50)'),
DataValue = Evt.value('value[1]', 'varchar(50)'),
DataText = Evt.value('text[1]', 'varchar(50)')
FROM
@input.nodes('/events/session/RingBufferTarget/event/data') as Tbl(Evt)
返回:
id uint32 0 NULL
timestamp uint64 0 NULL
process_utilization uint32 33 NULL
id uint32 0 NULL
(但显然需要事件名称)