Finally! Someone is talking about IIF and CHOOSE! 🙂
I like using ISNULL with the CHOOSE because CHOOSE returns a null if index is NULL or out of range. So:
IIF
(
PriorityCode IS NULL,
'Not Assigned',
IIF
(
PriorityCode BETWEEN 1 AND 4,
CHOOSE
(
PriorityCode,
'Low',
'Normal',
'High',
'Critical'
),
'Invalid Priority'
)
) AS PriorityName,
becomes (assuming you don't need to the know the difference betweeen a NULL index and an invalid index value)
ISNULL(CHOOSE
(
PriorityCode,
'Low',
'Normal',
'High',
'Critical'
),
'Invalid or Not Assigned'
) AS PriorityName,