locked
Condition within Query RRS feed

  • Question

  • User143067745 posted

    select be.detailhead, be.objecthead,abm.budget, case when abm.allocatebudget<=0 then 0  end   from BILLENTRY be  left join  BUDGETMASTER abm on be.detailhead=abm.detailhead and be.objecthead=abm.objecthead
    where be.serialno='12345';

    I want to check if abm.budget  is less than or equals 0 then I want output shoud be "No Budget" else output should be the value retrived from database.

    I mean to say that if write above query simply as:

    select be.detailhead, be.objecthead,abm.budget  from BILLENTRY be  left join  BUDGETMASTER abm on be.detailhead=abm.detailhead and be.objecthead=abm.objecthead
    where be.serialno='12345';

    Outpu is:

    DetailHead                   ObjectHead                  Budget

    1                                   2                                  5000

    2                                   9                                           

    But I want output as:

    DetailHead                   ObjectHead                  Budget

    1                                   2                                  5000

    2                                   9                                  No Budget

    How It will be possible??

    Thursday, April 19, 2012 7:22 AM

Answers

  • User551462331 posted

    try this

    select be.detailhead, be.objecthead,
    case abm.budget when null then 'No Budget' else abm.budget end as budget
    from BILLENTRY be  left join  BUDGETMASTER abm on be.detailhead=abm.detailhead and be.objecthead=abm.objecthead
    where be.serialno='12345';

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 19, 2012 7:33 AM

All replies

  • User1730632263 posted

    Budget = case when abm.allocatebudget<=0 then abm.allocatebudget + ''

    ELSE

    'No Budget

    END

    Thursday, April 19, 2012 7:31 AM
  • User551462331 posted

    try this

    select be.detailhead, be.objecthead,
    case abm.budget when null then 'No Budget' else abm.budget end as budget
    from BILLENTRY be  left join  BUDGETMASTER abm on be.detailhead=abm.detailhead and be.objecthead=abm.objecthead
    where be.serialno='12345';

    hope this helps...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 19, 2012 7:33 AM