19

I have a table named products.

Products
    Quantity
    5

I need to update Quantity by any value; for example, adding 3 to the current value, giving output like below:

Quantity
8

How can I write an SQL query to accomplish this?

1
  • 1
    update products set quantity = quantity + 3 ? (adding a where clause) Commented Nov 15, 2012 at 11:00

3 Answers 3

65
update products
set quantity = quantity + 3
Sign up to request clarification or add additional context in comments.

Comments

5
declare @table table(id int, quantity int)
insert into @table values(1, 5)

update @table
set quantity = quantity + 3
output inserted.quantity

Assuming that you actually wanted the value outputted. Don't forget any where clauses that may be needed

Comments

0

Jus in case, for string value, it should be as follows :

update products
set quantity = concat(quantity, '3')

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.