About
Pricing
Community
Teams
Start Free Trial
Log in
axnst2
asked on
1/8/2013
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!
Microsoft SQL Server 2005
Microsoft SQL Server
5
1
Last Comment
axnst2
8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Saurabh Bhadauria
1/8/2013
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Member_2_861731
1/8/2013
You can do just as you posted,
UPDATE MyTable
SET
Value2 = Value2 + 1
Steve Wales
1/8/2013
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
Select all
Open in new window
awking00
1/8/2013
I assume you have a where clause that will filter only those rows you wish to update.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
axnst2
1/8/2013
ASKER
Thank you!
UPDATE MyTable
SET
Value2 = Value2 + 1