Is it possible to return a default value if one record return null

  • 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.

  • 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."

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply