1

I have this table

Type   Price
A1     900
A2     800
A3     700
A4     600

I want to execute a update query where the Prices for A1, A3 and A4 increased by 5% The price for A2 must be increased with 6,5%

I tried to use Case or IIF and many more. But i cant figure out how i can put this in one query.

1
  • Why is 'A2' handled differently? If you're hard-coding , just use a where clause. SET Price = price + (price * .05) where type <> 'A2'`, etc Commented Oct 31, 2014 at 16:24

2 Answers 2

3

Something like the following should work. I

UPDATE <table>
SET PRICE = IIF([TYPE] IN ("A1","A3", "A4"); [Price]*1,05; [Price]*1,065)
Sign up to request clarification or add additional context in comments.

1 Comment

Replace ";" with "," and "," with "." if you are not working with german locales: UPDATE <table> SET PRICE = IIF([TYPE] IN ("A1", "A3", "A4"), [Price] * 1.05, [Price] * 1.065)
2

You can use a switch expression:

UPDATE my_table
SET    price = price * SWITCH (
                          type IN ('A1', 'A3'), 1.05,
                          type = 'A4', 1.065)
WHERE  type IN ('A1', 'A3', 'A4')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.