Greetings All,
I was asked to get a list of events and how often they occurred on which servers so I dug into the Event and EventDetail tables to try and get that info. I came up with the query below but it takes forever to run. Is there a more efficient way to write this query so I may also use it with Linked Servers so I can span QDB's in one SSRS Report? As always I most appreciate any help.

______________________________

DECLARE @Days as INT
set @Days = 1

--Get UTC Time
declare @UTCtd AS datetime
set @UTCtd = getutcdate()

--Get Today's Date and Time
declare @TodayTD AS datetime

set @TodayTD = GETDATE()

--Get Time Zone Informaiton
declare @TimeDif as int
set @TimeDif = DATEDIFF(hh, getutcdate(), getdate())

select
e.MachineName,
ed.AgentMsglong,
ed.AgentMsgshort,
DATEADD (HH,@TimeDif,dbo.fnSQLDateTime (ed.FirstOccurTime)) as FirstOccurTime,
DATEADD (HH,@TimeDif,dbo.fnSQLDateTime (e.LastOccurTime)) as LastOccurTime
from
dbo.Event as e
inner join dbo.EventDetail as ed on e.eventid = ed.eventid
where
e.KPName like '%NT_General_EventLog'
and
ed.AgentMsglong not like '%USER32%'
and
DATEDIFF(DD, @TodayTD, (DATEADD (HH,@TimeDif,dbo.fnSQLDateTime (e.LastOccurTime)))) * -1 <= @Days
and
ed.AgentMsglong like '%6008%'
or
ed.AgentMsgshort like '%6008%'