Sql Update - 添加当前值

时间:2016-04-18 13:06:36

标签: c# sql

假设我的数据库中有列:

(database)
Value1 = 3
Value2 = 5
Value3 = 6
Value4 = 7

我有4个int:

int v1 = 1;
int v2 = 2;
int v3 = 3;
int v4 = 4;

我如何更新我的数据库,所以我将这个int值添加到当前的db值,所以在最后我会得到

(database)
Value1 = 4
Value2 = 7
Value3 = 9
Value4 = 11

1 个答案:

答案 0 :(得分:1)

试试这个

update table1 
   set Value1 = Value1 + @v1,
       Value2 = Value2 + @v2,
       Value3 = Value3 + @v3,
       Value4 = Value4 + @v4