create sql str with special condition

  • create sql str with special condition

    hellow

    I have 2 table

    Table a(code, price, check)

    Table b(code, percent)

    I want to create a sql string such below:

    Select a.code, a.price, (price * percent) as new_field

    From a,b

    Where a.code = b.code

    And this condition must be consider in sql str:

    If (check = 1)

    {

    New_field = price * percent

    }

    Else

    {

    New_field = price * percent * 8

    }

    Now how can put above condition in sql str?

    Thanks very much

  • Select a.code, a.price, (price * percent * case when check = 1 then 1 else 8 end) as new_field

    From a,b

    Where a.code = b.code

    ?

    I Have Nine Lives You Have One Only
    THINK!

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

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