BOSS BOSS - 1 year ago 52
SQL Question

sql server query to add value to existing value

I have a table with few columns, one of these columns called _bandwidth and the value inside it is decimal.

So i wanna type a sql query that adds values to existing value.

Say the value of _bandwidth of user id 1 is 150.000 and i wanna add 200 to this value so sum would be 350.000

This is the query i typed but it didin't work.

update users set _bandwidth = (select _bandiwdth from users where _ID = 1) + 150 where _ID = 1

Also did something like:

update users set _bandwidth += 200 where _ID = 1

Of course they are wrong, but i hope you understand what i wanna achieve.

Thanks a lot in advance.

Found the solution and the answer would be:

update users set _bandwidth = _bandwidth + 200 where _ID = 1

Answer Source
SET _bandwidth = _bandwidth + 200

would work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download