Solved

Return value only if column is NULL

Posted on 2013-01-17
6
378 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:Starr Duskk
  • 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 2

Author Closing Comment

by:Starr Duskk
ID: 38789639
perfect!
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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 2

Author Comment

by:Starr Duskk
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

12 Experts available now in Live!

Get 1:1 Help Now