[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Update statement

Posted on 2007-08-05
4
Medium Priority
?
213 Views
Last Modified: 2010-03-19
Hello all,

I have a field in my database called
'number' and contains integer values.
How can I run an sql statement and add 15
to all the records?

For example:
I would like to change this:   [itemID], [Name], [Number]
                                              [221], [John White], [1000]
to this:
 [221], [John White], [1015]

So, what it should do is increase the value of 'number' by 15 for all the records in my table.

Thanks
0
Comment
Question by:nectarios777
  • 3
4 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 19633646
try this

update yourtablename set Number = Number + 15
0
 
LVL 33

Accepted Solution

by:
hongjun earned 200 total points
ID: 19633648
Please note it will update ALL records!!!
If this is what you want, then proceed.

To update only certain records, you should do it with a WHERE clause.
E.g.

update yourtablename set Number = Number + 15 where ItemID = 221
0
 
LVL 1

Author Comment

by:nectarios777
ID: 19633712
hello,

thanks for your answer.
Is there a way to update with random numbers instead of fixed values
such as 15?
0
 
LVL 33

Expert Comment

by:hongjun
ID: 19633723
I would suggest you post a new question to address this.

hongjun
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question