I’m trying to parse this out. I want one record for each event, so I need a way to query each event separately.
But I’d like it to look something like this:
Event Name || ID || Timestamp || process_utilization
---------------------------------------------------------------------------------------------
scheduler_monitor_system_heal_ring_buffer_recorded || 0 || 0 || 33
Here’s the 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>
EDIT:
Alternatively, if we could return rows that look like this, that would be Just Fine:
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
EDIT: (Thanks, Mark)
Using Mark’s code, I got this which is 98% of what I want – just need the Event Name.
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)
which returns:
id uint32 0 NULL
timestamp uint64 0 NULL
process_utilization uint32 33 NULL
id uint32 0 NULL
(but, obviously, need the event name)
Assuming you have your XML in a variable called
@input, try this:With your sample XML, I get an output of: