Hello,
I have a question about an existing report I have.
Currently the report runs based upon the current date & subtracts 1 to get the last months date range.
It turns out my boss is NOT running the report on the 1st of each month as I told him he needed to for the results to be the previous months values.
As a result I now have to ask for your help in getting results filtered by each month and not just the last month from when I execute the report.
Ideally having the report run (whatever day I chose to run it) and it will generate each previous months Outage (for up to 12 months).
Would anyone be kind enough to help me with the sql query?
I believe the specific changes would have to impact the "eventtime between" line of code.
Here is how my current report looks in sql.
SELECT
Nodes.Caption,
StartTime.EventTime,
DATEDIFF(Mi, StartTime.EventTime,
(SELECT TOP 1
EventTime
FROM Events AS Endtime
WHERE EndTime.EventTime > StartTime.EventTime AND EndTime.EventType = 5
AND EndTime.NetObjectType = 'N'
AND EndTime.NetworkNode = StartTime.NetworkNode
ORDER BY EndTime.EventTime)) AS OutageDurationInMinutes
FROM Events StartTime INNER JOIN Nodes ON StartTime.NetworkNode = Nodes.NodeID
WHERE (StartTime.EventType = 1) AND (StartTime.NetObjectType = 'N') AND (nodes.caption like '%USRTAVIN%' OR nodes.caption like '%USRTRNYNY80%' OR nodes.caption like '%USRTRLACA001%') and
eventtime between (DATEADD(m, DATEDIFF(m, 0, getdate()) -1 , 0)) AND (DATEADD(m, DATEDIFF(m, 0, getdate()) , 0))
--ORDER BY Nodes.Caption ASC
ORDER BY StartTime.EventTime ASC