Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 updating int without selecting it

Author  Topic 

tokue
Starting Member

16 Posts

Posted - 2010-08-20 : 08:04:59
Hi everybody,
perhaps my problem is easy for you.
I have a field with data type (int) in one of my tables, I want a sql statement that update that field without selecting it first and making calculations and then updating it, I tried this statement but it doesn't work:

UPDATE items SET itemAmount = (+ 5) WHERE ID=@ID

what I am trying to do is updating that field by adding the number 5 to what ever number it has....
Is that possible?

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-08-20 : 08:12:30
UPDATE items SET itemAmount = itemAmount + 5 WHERE ID=@ID

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

tokue
Starting Member

16 Posts

Posted - 2010-08-20 : 08:15:27
I found the solution by playing around

UPDATE items SET itemAmount = (itemAmount + 5) WHERE ID=@ID
Go to Top of Page

tokue
Starting Member

16 Posts

Posted - 2010-08-20 : 08:17:25
I wrote my last words before seeing your answer dear vaibhavktiwari83, Thank you...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-20 : 08:35:11
If the version is from 2008,

UPDATE items SET itemAmount+ = 5 WHERE ID=@ID


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -