SWQL CASE Function

i would like to display the severity of each alarm , i noticed that the value returned is a number and i'm working on a way to change the value into something else .

i tried the CASE function as shown belwon but i'm getting error in the syntax:

SELECT

OAH.AlertObjects.AlertConfigurations.DisplayName AS [Alert Name]

, OAH.AlertObjects.AlertConfigurations.AlertID AS [Alert ID]

, COUNT( AlertHistoryID ) AS [Last 30 Days]

, CASE

When AC.Severity=1 then 'Warning'

When AC.Severity=2 then  'Critical'

ELSE AC.Severity

end AS [ Criticité ]

FROM Orion.AlertHistory OAH

INNER JOIN Orion.AlertConfigurations as AC on AC.AlertID = OAH.AlertObjects.AlertConfigurations.AlertID

WHERE EventType = 0 and  oah.AlertObjects.AlertConfigurations.AlertID IN ('714','618','735','732','941','942')  AND  OAH.TimeStamp > GetUtcDate()-30

GROUP BY oah.AlertObjects.AlertConfigurations.AlertID

this CODE is working Fine without the CASE function.

Thanks for any help you can offer.

Parents
  • The issue here is that the output from the case part can be a mix of string and integer.

    If AC.Severity is 1 or 2 you get a string. Else you get an integer. You are not allowed to mix that in one column. So you have to turn the integer to a string with ToString(). Like this:

    , CASE
        When AC.Severity=1 then 'Warning'
        When AC.Severity=2 then  'Critical'
        ELSE ToString(AC.Severity)
    end AS [ Criticité ]

    Hope that helps.

Reply
  • The issue here is that the output from the case part can be a mix of string and integer.

    If AC.Severity is 1 or 2 you get a string. Else you get an integer. You are not allowed to mix that in one column. So you have to turn the integer to a string with ToString(). Like this:

    , CASE
        When AC.Severity=1 then 'Warning'
        When AC.Severity=2 then  'Critical'
        ELSE ToString(AC.Severity)
    end AS [ Criticité ]

    Hope that helps.

Children