Link to home
Start Free TrialLog in
Avatar of axnst2
axnst2Flag for United States of America

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!
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Bhadauria
Saurabh Bhadauria
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_861731
You can do just as you posted,

UPDATE MyTable
SET
        Value2 = Value2 + 1
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

Open in new window

I assume you have a where clause that will filter only those rows you wish to update.
Avatar of axnst2

ASKER

Thank you!