SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Case statement


Case statement

Author
Message
VSSGeorge
VSSGeorge
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4687 Visits: 1586
Please help to write the SQL query in a more cleaner way...

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

Thanks
HanShi
HanShi
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18483 Visits: 3787
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’! **
andrea.gnemmi
andrea.gnemmi
SSC-Addicted
SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)SSC-Addicted (429 reputation)

Group: General Forum Members
Points: 429 Visits: 164
I agree, I would use a COALESCE statement.
Amit Raut
Amit Raut
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1869 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search