axnst2
asked on
Increment an int value by one in a single update
Hi Experts,
When I do an update on the table I need to automatically increment one of the fields something like so:
UPDATE MyTable
SET
Value1 = 'NewValue'
Value2 = Value2 + 1
Is there a way to do this somehow?
Value2 is used kind of like a version number! Don't ask!
Thanks!
When I do an update on the table I need to automatically increment one of the fields something like so:
UPDATE MyTable
SET
Value1 = 'NewValue'
Value2 = Value2 + 1
Is there a way to do this somehow?
Value2 is used kind of like a version number! Don't ask!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem you may be getting is your syntax, you're missing a comma, just before 'Value2 =':
UPDATE MyTable
SET
Value1 = 'NewValue',
Value2 = Value2 + 1
I assume you have a where clause that will filter only those rows you wish to update.
ASKER
Thank you!
UPDATE MyTable
SET
Value2 = Value2 + 1