Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Is it possible to return a default value if one record return null Expand / Collapse
Author
Message
Posted Tuesday, March 25, 2014 8:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 1:09 AM
Points: 1, Visits: 7
Hi, I am new in SQL. Now I want to handle the case that if I am selecting for the Name and Unit in table of fruit where Name in ('apple','orange','banana').
However, there are no item call 'banana' in database yet and I want to have a default value for 'banana' like

Name Unit
apple 10
orange 20
banana 0



How can I do this instead of just getting

Name Unit
apple 10
orange 20


Can I do this by using Union??Thanks!


Furthermore information, actually I am doing this with my C# program. Users can search the Unit of the item by using string [] and now I want to have a default value if there is a item can't be search.
Post #1554745
Posted Tuesday, March 25, 2014 11:12 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 2:56 AM
Points: 2,603, Visits: 2,061
You can also add clause
"where/and unit <> 0"
OR
"where/and unit > 0"




---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Post #1554771
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse