Hey Guys,
So I'm in the process of creating a new Alert View where we can monitor all active alerts, similar to the 'Active Alerts' page.
In this table, I want the alert notes as a column. This was easy enough, however, if alert notes have been added, I get a new row for every variation of notes when I just want to show the latest notes associated with the alert.
I've tried a few things, but I can't seem to come up with a way that doesn't involve subqueries.
If I use any subqueries, I get the 'SWQL Studio, subqueries not supported' message
Here is a simplified version of my queries
SELECT aa.AlertObjectID ,ah.AlertObjectID, ah.Message, ah.TimeStamp
, (SELECT TOP 1 Message FROM Orion.AlertHistory WHERE AlertObjectID = aa.AlertActiveID ORDER by TimeStamp DESC) AS [Note]
From Orion.AlertActive aa
join Orion.AlertObjects o on aa.alertobjectid=o.alertobjectid
LEFT join Orion.Nodes p on p.nodeid=relatednodeid
left join orion.alerthistory ah on ah.AlertActiveID=aa.AlertActiveID and ah.EventType in (2,3)
ORDER by o.AlertActive.TriggeredDateTime DESC
This one has the subquery in the select and just grabs the top note for the active alert, thought maybe I might need to add the DISTINCT keyword but this just didn't run so couldn't debug
SELECT aa.AlertObjectID ,ah.AlertObjectID, ah.Message, ah.TimeStamp
From Orion.AlertActive aa
join Orion.AlertObjects o on aa.alertobjectid=o.alertobjectid
LEFT join Orion.Nodes p on p.nodeid=relatednodeid
left join orion.alerthistory ah on ah.AlertActiveID=aa.AlertActiveID and ah.EventType in (2,3)
WHERE ah.TimeStamp IN (
SELECT TOP 1 TimeStamp
FROM Orion.AlertHistory
WHERE AlertObjectId = aa.AlertActiveID
ORDER BY TimeStamp DESC
)
ORDER by o.AlertActive.TriggeredDateTime DESC
This one has the subquery in the WHERE section. The idea being, the timestamp for the alert history object has to equal the latest one.
Again couldn't run so couldn't debug