Case statement

  • Please help to write the SQL query in a more cleaner way...

    CASE ISNULL(TCBOV.cboValueName, '') WHEN '' THEN ''

    ELSE TCBOV.cboValueName

    END

    Thanks

  • Junglee_George (9/4/2013)


    Please help to write the SQL query in a more cleaner way...

    CASE ISNULL(TCBOV.cboValueName, '') WHEN '' THEN ''

    ELSE TCBOV.cboValueName

    END

    Thanks

    You don't have to use a CASE statement for this, just a ISNULL or COALESCE within the SELECT.

    SELECT ISNULL(TCBOV.cboValueName, '')

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • I agree, I would use a COALESCE statement.

  • If you need to handle another condition along with NULL, you may write something like

    CASE

    WHEN TCBOV.cboValueName IS NOT NULL THEN

    CASE TCBOV.cboValueName

    WHEN 10 THEN 'Value1'

    WHEN 20 THEN 'Value2'

    ELSE TCBOV.cboValueName

    END

    ELSE 'No Value'

    END

Viewing 4 posts - 1 through 3 (of 3 total)

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