Skip to content
Advertisement

SQL CASE Statement for no data

I have a table that has process engines 1,2,3,4,5,6 with a running status. When one of the engines is down the record gets deleted from the table. Using a case statement I can display the first engine that is down but how do I go about displaying the engines if 2 or more engines are down. For e.g. how do I make this query display PE 2 IS DOWN and PE 4 is DOWN if both the engines are down. Right now it displays only the first engine in the list that is down .

Advertisement

Answer

Instead of case, using union all for the two different cases, all good versus some not running. Sub query factoring to reduce repeated code.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement