SQL 如何使用sql查询向现有值添加值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13396119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:07:49  来源:igfitidea点击:

how to add a value to existing value using sql query

sqlsql-server-2008

提问by user475464

i have table named products

我有名为产品的表

Products

产品

Quantity
5

i need to update Quantity by any value for example '5+3'

我需要通过任何值更新数量,例如“5+3”

need output like below

需要像下面这样的输出

Quantity
8

How i write query for this?

我如何为此编写查询?

回答by juergen d

update products
set quantity = quantity + 3

回答by Manatherin

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

假设您实际上想要输出的值。不要忘记任何可能需要的 where 子句