Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Case statement Expand / Collapse
Author
Message
Posted Wednesday, September 4, 2013 12:38 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: 2 days ago @ 5:07 AM
Points: 609, Visits: 1,135
Please help to write the SQL query in a more cleaner way...

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

Thanks
Post #1491150
Posted Wednesday, September 4, 2013 12:57 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:56 PM
Points: 2,397, Visits: 2,936
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’! **
Post #1491155
Posted Tuesday, September 10, 2013 1:28 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 6:59 AM
Points: 232, Visits: 159
I agree, I would use a COALESCE statement.
Post #1493022
Posted Wednesday, September 11, 2013 6:29 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 6:12 PM
Points: 827, Visits: 342
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
Post #1493964
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse