DoLoop DoLoop - 7 months ago 15
SQL Question

Sql Update - add on current value

Lets say i have columns in my database:

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


and i have 4 int:

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


How can i update my database so i add this int values to current db values so in final i would get

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

Answer

Try this

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