• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Return value only if column is NULL

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
Starr Duskk
Asked:
Starr Duskk
  • 3
  • 2
2 Solutions
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
thombeckCommented:
Hi,


use :

select
   Case when MenuName is Null
     Then 'Not Used'
     Else ''
    End
0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
perfect!
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
yours errored when I used it with an integer field and the other did not.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Fair enough
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now