Solved

Return value only if column is NULL

Posted on 2013-01-17
6
376 Views
Last Modified: 2013-01-17
I want to return a value only if the column is null.

isnull(MenuName, 'Not Used') AS MenuUsage

Something like the above... If it is null, I want the column to be 'Not Used'
If it is not null, I want it blank and to say nothing, I don't want it to return the Menu Name.

How do I do that?

thanks!
0
Comment
Question by:BobCSD
  • 3
  • 2
6 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 20 total points
ID: 38789560
CASE COALESCE(MenuName, 'Not Used')
   WHEN 'Not Used' THEN 'Not Used' ELSE '' END

COALESCE eturns the first non-null value, which will either be the contents of MenuName, or in this case an empty string ''
0
 
LVL 2

Accepted Solution

by:
thombeck earned 480 total points
ID: 38789568
Hi,


use :

select
   Case when MenuName is Null
     Then 'Not Used'
     Else ''
    End
0
 
LVL 1

Author Closing Comment

by:BobCSD
ID: 38789639
perfect!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 65

Expert Comment

by:Jim Horn
ID: 38789659
Please explain how my solution did not meet your needs.
After re-reading your question a couple of times I'm not seeing anything that was missed.
0
 
LVL 1

Author Comment

by:BobCSD
ID: 38789773
yours errored when I used it with an integer field and the other did not.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38789927
Fair enough
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now