October 28, 2014 at 12:01 pm
Is there a better way to approach this ? Sorry there was an error earlier .
Case when Server_Excluded <> 'Yes' and Aged30 > 0 Then 'Green'
when Server_Excluded <> 'Yes' and Group= '' then 'Amber'
when Server_Excluded <> 'Yes' and ImportantAged30 >0 Then 'Amber'
End as Status
October 28, 2014 at 12:49 pm
That seems fine to me. An alternative could be:
Case when Server_Excluded <> 'Yes' and Aged30 > 0 Then 'Green'
when Server_Excluded <> 'Yes' and (Group= '' OR ImportantAged30 >0) Then 'Amber'
End as Status
I can't say that one is better than the other, it's mainly based on your preferences.
October 29, 2014 at 9:39 am
I see. Thank you
October 29, 2014 at 9:54 am
What is Server_Excluded = 'Yes'? In other words, don't forget the ELSE.
October 29, 2014 at 9:59 am
You could also use nested CASE functions to avoid repeating the Server_Excluded test.
CASE WHEN Server_Excluded <> 'Yes' THEN
CASE WHEN Aged30 > 0 THEN 'Green'
WHEN Group = '' OR ImportantAged30 > 0 THEN 'Amber' END
END
It's a matter of style preference, I doubt there's any measurable performance difference.
The main consideration I would use is which version looks easier to understand and maintain.
October 29, 2014 at 7:51 pm
Just to know, how many possible values do you have for the Server_Excluded column? Does it allow NULLs, as well?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply