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


Case statement


Case statement

Author
Message
VSSGeorge
VSSGeorge
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2053 Visits: 1578
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
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8204 Visits: 3718
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
Old Hand
Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)Old Hand (301 reputation)

Group: General Forum Members
Points: 301 Visits: 164
I agree, I would use a COALESCE statement.
Amit Raut
Amit Raut
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

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