我正在尝试在包装好的数组中查找元素数。以下是方案。
数组不需要排序。
它与for循环一起使用,效率极低。有更好的方法吗?
日期位于包装的数组中(未排序)-用户将指定开始日期和结束日期,并且必须计算它们之间的元素数。
select xe.TraceFileName
, xe.TraceEvent
, xe.EventDataXML.value('(/event/data[@name="EventSubclass"]/value)[1]', 'int') as EventSubclass
, xe.EventDataXML.value('(/event/data[@name="ServerName"]/value)[1]', 'varchar(50)') as ServerName
, xe.EventDataXML.value('(/event/data[@name="DatabaseName"]/value)[1]', 'varchar(50)') as DatabaseName
, xe.EventDataXML.value('(/event/data[@name="NTDomainName"]/value)[1]', 'varchar(50)') as NTDomainName
, xe.EventDataXML.value('(/event/data[@name="NTUserName"]/value)[1]', 'varchar(50)') as NTUserName
, xe.EventDataXML.value('(/event/data[@name="NTCanonicalUserName"]/value)[1]', 'varchar(50)') as NTCanonicalUserName
, xe.EventDataXML.value('(/event/data[@name="ConnectionID"]/value)[1]', 'int') as ConnectionID
, xe.EventDataXML.value('(/event/data[@name="StartTime"]/value)[1]', 'datetime') as StartTime
, xe.EventDataXML.value('(/event/data[@name="EndTime"]/value)[1]', 'datetime') as EndTime
, xe.EventDataXML.value('(/event/data[@name="Duration"]/value)[1]', 'bigint') as Duration
, xe.EventDataXML.value('(/event/data[@name="TextData"]/value)[1]', 'varchar(max)') as TextData
into #List
from
(
select [file_name] as TraceFileName
, object_name as TraceEvent
, convert(xml, event_data) as EventDataXML
from sys.fn_xe_file_target_read_file('path\filename*.xel', null, null, null)
) xe;
代码效率不高-并希望针对性能进行优化。