Building a Support Ticket Triage Report with IIF() and CHOOSE() in SQL Server

  • Comments posted to this topic are about the item Building a Support Ticket Triage Report with IIF() and CHOOSE() in SQL Server

  • 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,

     

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply