Kayla Thompson
Kayla Thompson

Reputation: 13

I am trying to update multiple values in one column

This is the question:

-If the price of the phone is less than R8000, then there is a price increase of R100 -If the price of the phone is R8000 or more, then there is a price reduction/decrease of 10% on the original selling price of the phone.

This is what I have tried:

UPDATE       tblPhoneDetails
SET          CellPhone_UnitPrice = CellPhone_UnitPrice - 100
WHERE        (CellPhone_UnitPrice < '8000'),
SET          CellPhone_UnitPrice = CellPhone_UnitPrice - CellPhone_UnitPrice * 0.1
WHERE        (CellPhone_UnitPrice > '8000')

Upvotes: 1

Views: 26

Answers (1)

GMB
GMB

Reputation: 222482

I think you want a case expression:

update tblphonedetails
set cellphone_unitprice = case 
    when cellphone_unitprice < 8000 then cellphone_unitprice - 100 
    else cellphone_unitprice * 0.9
end

Upvotes: 1

Related Questions